青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

posts - 17,  comments - 2,  trackbacks - 0


System::String -> std::string
A reader asks,
 
Sender: Erik Brendengen
 
Is there an easy way to convert from String^ to std::string?
             Does String ^s = std::string( “bla”).c_str(); work the other way?
 
This is a FAQ, one that I myself bumped into when I had to pass a System::String retrieved from System::Windows::Forms::TextBox to a native program that expected a std::string.
 
There are generally two conversion strategies, depending on which side of the managed/native fence you wish to do the conversion work. Here are two methods making use of the PtrToStringChars( String^ ) utility from the vcclr.h header file that is part of Visual C++. Note that these are written in the new C++/CLI syntax – and that these are adapted from an internal FAQ ...
 
#include <stdlib.h>
#include <vcclr.h>
#include <string>
using namespace System;
 
bool To_CharStar( String^ source, char*& target )
{
    pin_ptr<const wchar_t> wch = PtrToStringChars( source );
    int len = (( source->Length+1) * 2);
    target = new char[ len ];
    return wcstombs( target, wch, len ) != -1;
}
 
bool To_string( String^ source, string &target )
{
    pin_ptr<const wchar_t> wch = PtrToStringChars( source );
    int len = (( source->Length+1) * 2);
    char *ch = new char[ len ];
    bool result = wcstombs( ch, wch, len ) != -1;
    target = ch;
    delete ch;
    return result;
}
 
As to the second question, does String^ s = ns.c_str() work? Yes.
Published Wednesday, June 02, 2004 2:56 PM by slippman
Comments
 
Are there any plans to, ahem, extend std::string to include constructors and extraction methods for String^, like ATL::CString currently has? 
As a sidenote, this is not the first time I find myself wanting one or two features from CString in std::string, to make the decision for which of the two classes to use for a native Windows C++ application a bit easier... 
Either way, I'm really looking forward to the new C++/CLI. Actually, the /clr switch works amazingly well even today.
June 3, 2004 10:27 AM
 
In Whidbey we'll be supplying much more direct approach to do this type of marshalling via a library. 

void F( String^ s ) 

string s1 = marshal_to<string>( s ); 
String^ s2 = marshal_to<String^>( s1 ); 


If you already have a char*, and want to get a System::String from it, all you have to do is this: 

void F( const char* s ) 

String^ s1 = gcnew String( s ); 
}
June 4, 2004 3:01 PM
 
as david larsson's ahem indicates, extending the standard ISO-C++ string independent of a standard's body is, i think, unlikely at this point. however, as anson's mail indicates, there is lots of thought being given on how to help users interoperate between the native and managed platforms, and david's request for support in this is not at all unreasonable.
June 17, 2004 9:26 AM
 
Yves Dolce -- the conscience of the blogs -- rightly pointed out that they two conversion samples needlessly prolong the pinning of the internal System::Char array of the String, and has proposed the following preferred alternatives, 

bool To_CharStar( String^ source, char*& target ) 



int len = (( source->Length+1) * 2); 

target = new char[ len ]; 

pin_ptr<const wchar_t> wch = PtrToStringChars( source ); 

return wcstombs( target, wch, len ) != -1; 





bool To_string( String^ source, string &target ) 



int len = (( source->Length+1) * 2); 

char *ch = new char[ len ]; 

bool result ; 



pin_ptr<const wchar_t> wch = PtrToStringChars( source ); 

result = wcstombs( ch, wch, len ) != -1; 



target = ch; 

delete ch; 

return result; 



June 17, 2004 12:16 PM
 
In To_string(), shouldn't 

delete ch; 

actually be 

delete[] ch; 

Since you're allocating an array, you really should use the array deletion expression...
July 2, 2004 5:00 AM
 
you are correct. it is a bad habit for an old dog who was programming with the language before this was added, and of course in current implementations, its absence is actually both non-fatal and possibly more efficient.
July 7, 2004 11:39 AM
Anonymous comments are disabled
posted on 2008-11-06 17:31 BeyondCN 閱讀(4658) 評論(1)  編輯 收藏 引用 所屬分類: .NET
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美专区福利在线| 欧美韩日视频| 韩国免费一区| 久久一区国产| 玖玖综合伊人| 日韩午夜激情av| 亚洲精品综合久久中文字幕| 欧美精品 日韩| 在线视频你懂得一区| 亚洲性色视频| 国产一区二区精品久久| 女同性一区二区三区人了人一| 久久人人九九| 一区二区三区免费网站| 亚洲精品午夜精品| 国产欧美日韩一区二区三区在线观看| 午夜电影亚洲| 久久久久中文| 99热在这里有精品免费| 在线一区二区三区四区| 国产亚洲精品久久久久动| 欧美凹凸一区二区三区视频| 欧美高潮视频| 欧美影院精品一区| 久久裸体视频| 亚洲字幕在线观看| 久久精品国产免费看久久精品| 亚洲精品久久久蜜桃 | 樱桃国产成人精品视频| 欧美大片免费看| 欧美性一区二区| 美女成人午夜| 欧美亚洲第一页| 美女露胸一区二区三区| 国产精品分类| 亚洲第一视频| 国产情人节一区| 亚洲三级电影全部在线观看高清| 国产精品高清在线观看| 欧美刺激性大交免费视频| 国产精品久久二区二区| 欧美激情精品久久久久| 国产麻豆综合| 夜夜嗨av一区二区三区中文字幕| 激情久久五月| 亚洲综合色视频| 一区二区三区四区五区精品视频| 久久久福利视频| 欧美一区1区三区3区公司| 欧美激情国产高清| 欧美激情第4页| 狠狠v欧美v日韩v亚洲ⅴ| 日韩亚洲欧美中文三级| 亚洲三级视频在线观看| 久久精品国产第一区二区三区最新章节 | 亚洲欧洲在线看| 亚洲电影专区| 免费成人av资源网| 在线观看日韩av电影| 翔田千里一区二区| 午夜久久美女| 欧美丝袜一区二区| 一本色道久久综合亚洲精品不卡| 伊人一区二区三区久久精品| 亚洲欧美久久久| 亚洲欧美网站| 国产精品私人影院| 亚洲欧美清纯在线制服| 亚洲欧美日韩精品久久亚洲区| 欧美日韩a区| av成人激情| 亚洲视频日本| 国产精品美女久久久久久2018| 夜夜爽av福利精品导航| 亚洲图片你懂的| 国产伦精品一区二区| 欧美一级理论性理论a| 久久国产乱子精品免费女| 国产一区二区三区不卡在线观看 | 免费观看30秒视频久久| 伊人成人在线视频| 男人的天堂成人在线| 亚洲国产高清自拍| 一本色道久久综合亚洲精品按摩 | 国模精品娜娜一二三区| 久久成人精品电影| 免费成人高清在线视频| 亚洲高清不卡av| 欧美成人一区二区在线| 亚洲精品欧美激情| 亚洲一区二区三区视频播放| 国产精品jizz在线观看美国| 亚洲一区区二区| 老司机久久99久久精品播放免费 | 久久国产99| 亚洲国产精品激情在线观看| 欧美成人按摩| 国产精品99久久久久久久久| 久久理论片午夜琪琪电影网| 91久久午夜| 国产精品青草综合久久久久99| 欧美一区二区三区久久精品茉莉花| 免费在线成人| 亚洲宅男天堂在线观看无病毒| 国产欧美在线播放| 欧美成人一区二区三区| 亚洲天天影视| 欧美激情视频一区二区三区不卡| 亚洲色图制服丝袜| 精品999在线观看| 欧美日本久久| 久久精品中文字幕一区二区三区| 最新69国产成人精品视频免费| 香蕉久久一区二区不卡无毒影院 | 一本到12不卡视频在线dvd| 国产精品一区二区久久| 欧美成人r级一区二区三区| 亚洲欧美日韩精品一区二区| 欧美激情视频在线免费观看 欧美视频免费一 | 亚洲国产成人av| 国产精品亚洲第一区在线暖暖韩国| 免费一级欧美片在线播放| 亚洲性视频h| 亚洲精品亚洲人成人网| 免费成人性网站| 欧美一区成人| 亚洲午夜精品一区二区三区他趣| 在线观看中文字幕亚洲| 国产精品一区视频| 欧美日本免费| 欧美激情在线免费观看| 久久久久女教师免费一区| 亚洲视频在线观看网站| 日韩亚洲国产精品| 亚洲人成在线免费观看| 麻豆国产精品777777在线| 久久国产高清| 久久精品国产99国产精品澳门| 正在播放亚洲| 夜夜嗨av色一区二区不卡| 最新成人av网站| 亚洲精品美女在线观看| 91久久精品一区二区别| 1769国产精品| 亚洲国内精品| 最新高清无码专区| 亚洲人成毛片在线播放女女| 亚洲国产精品尤物yw在线观看| 国内一区二区在线视频观看 | 欧美视频观看一区| 欧美午夜视频在线观看| 欧美日韩伦理在线免费| 欧美日韩一区成人| 国产精品成人免费视频| 国产精品热久久久久夜色精品三区 | 亚洲国产成人av好男人在线观看| 欧美风情在线观看| 亚洲国产99| 日韩视频一区二区三区在线播放| 亚洲精品五月天| 亚洲先锋成人| 久久不射2019中文字幕| 久久在线播放| 欧美日韩播放| 国产精品自拍三区| 精久久久久久| 亚洲精品免费一二三区| 99综合电影在线视频| 亚洲欧美日本另类| 久久久久一区| 91久久线看在观草草青青| 亚洲午夜av在线| 欧美在线视频免费| 欧美激情a∨在线视频播放| 欧美视频一区二区三区四区| 国产日韩免费| aa成人免费视频| 欧美在线精品免播放器视频| 老鸭窝91久久精品色噜噜导演| 亚洲福利av| 午夜欧美精品久久久久久久| 久久久午夜电影| 欧美日韩精品国产| 黄色精品在线看| 亚洲网在线观看| 老巨人导航500精品| 99热这里只有成人精品国产| 欧美在线免费观看亚洲| 欧美日本亚洲| 在线观看成人一级片| 亚洲综合精品四区| 亚洲国产毛片完整版 | 免费成人av| 国产午夜精品全部视频播放 | 国产精品国产三级国产专播精品人 | 激情综合电影网| 亚洲免费婷婷| 亚洲国产日韩精品| 久久九九99| 国产日韩精品一区二区三区在线 |