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

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 閱讀(4647) 評論(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>
            在线观看亚洲专区| 欧美gay视频激情| 六月婷婷一区| 久久亚洲欧美| 久久久在线视频| 久久久久国产精品厨房| 久久精品99久久香蕉国产色戒 | 一二三区精品福利视频| 亚洲国产天堂久久综合| 欧美大色视频| 亚洲国产婷婷香蕉久久久久久| 亚洲第一成人在线| 一区二区欧美激情| 欧美亚洲免费电影| 久久阴道视频| 欧美日韩在线播放| 国产亚洲欧洲| 亚洲国产精品久久91精品| 国模吧视频一区| 欧美专区一区二区三区| 亚洲日韩视频| 亚洲欧美日韩一区二区三区在线观看| 欧美主播一区二区三区美女 久久精品人| 久久九九免费视频| 亚洲黄色天堂| 午夜久久久久久| 欧美成人精品1314www| 欧美色一级片| 亚洲第一天堂无码专区| 亚洲天堂激情| 免费日韩av| 亚洲视频axxx| 欧美成人一区二区三区| 国产精品色在线| 亚洲三级视频在线观看| 欧美一区观看| 99天天综合性| 嫩模写真一区二区三区三州| 国产九九精品视频| 一本色道久久综合狠狠躁篇怎么玩| 欧美在线精品免播放器视频| 亚洲国产成人av| 久久天天狠狠| 国产深夜精品| 亚洲免费在线看| 99这里有精品| 欧美激情亚洲激情| 在线视频成人| 久久综合激情| 久久av在线看| 国产精品视频免费观看| 在线性视频日韩欧美| 男女精品视频| 久久久99久久精品女同性| 国产精品综合av一区二区国产馆| 一区二区日本视频| 91久久国产综合久久蜜月精品| 狼人社综合社区| 国语自产精品视频在线看8查询8| 久久精品人人做人人综合| 亚洲欧美日韩成人高清在线一区| 国产精品成人免费精品自在线观看| 国内精品国产成人| 久久久久久久国产| 久久精品夜色噜噜亚洲a∨| 国产在线不卡视频| 欧美一区二区大片| 亚洲小说欧美另类婷婷| 国产精品日韩专区| 久久国产欧美日韩精品| 欧美综合77777色婷婷| 精品成人乱色一区二区| 欧美成人免费网| 欧美高清视频一区二区| 亚洲视频导航| 亚洲欧美日韩中文在线制服| 国产精品视频久久一区| 亚洲性夜色噜噜噜7777| 亚洲精品美女久久久久| 一区二区三区欧美在线观看| 一级成人国产| 国产亚洲一区二区三区在线观看| 久久精品国产精品亚洲| 欧美在线观看日本一区| 亚洲精品极品| 99精品欧美一区二区三区| 国产精品夜色7777狼人| 久久久亚洲欧洲日产国码αv| 久久躁狠狠躁夜夜爽| 一本色道久久综合狠狠躁的推荐| 亚洲视频免费看| 精品va天堂亚洲国产| 91久久线看在观草草青青| 欧美视频一区二区三区…| 久久av最新网址| 免费一级欧美片在线观看| 一区二区三区四区精品| 亚洲欧美日韩国产| 亚洲欧洲在线观看| 亚洲已满18点击进入久久| 一区二区三区在线免费播放| 亚洲片在线观看| 韩国三级电影久久久久久| 亚洲国产网站| 国内揄拍国内精品久久| 亚洲国产另类久久久精品极度| 欧美视频中文一区二区三区在线观看| 久久精品视频在线播放| 欧美日本一区| 欧美成人日本| 国产亚洲成人一区| 一区二区免费在线视频| 亚洲欧洲一区二区在线播放| 欧美一区二区黄| 亚洲一区精品视频| 欧美成ee人免费视频| 久久精品免费播放| 欧美三级视频在线播放| 亚洲黄色有码视频| 韩国精品在线观看| 亚洲亚洲精品三区日韩精品在线视频 | 久久久青草青青国产亚洲免观| 毛片av中文字幕一区二区| 欧美一区二区成人6969| 国产精品theporn| 亚洲精品一区二区三区四区高清| 亚洲东热激情| 久久久久这里只有精品| 久久国产福利国产秒拍| 国产精品国产三级国产普通话99 | 欧美福利视频一区| 影音先锋日韩资源| 欧美在线一二三四区| 欧美一级久久| 国产精品一二一区| 亚洲一区二区3| 亚洲电影中文字幕| 亚洲视频999| 亚洲综合清纯丝袜自拍| 99国产精品国产精品毛片| 久久久久久亚洲精品中文字幕 | 亚洲一区二区在线| 模特精品在线| 牛牛国产精品| 91久久精品国产91性色| 欧美成人免费视频| 欧美韩国日本综合| 亚洲精品视频在线观看免费| 免费在线观看精品| 欧美国产欧美亚州国产日韩mv天天看完整| 狠狠色狠狠色综合日日小说| 久久精品毛片| 欧美**人妖| 洋洋av久久久久久久一区| 欧美精品一区二区三区蜜桃| 亚洲精品久久久久久久久久久久久| 最近看过的日韩成人| 欧美极品一区| 夜夜爽www精品| 亚洲欧美日韩国产精品| 国产一区二区在线观看免费播放| 新67194成人永久网站| 麻豆乱码国产一区二区三区| 91久久国产综合久久蜜月精品| 欧美成人免费一级人片100| 99伊人成综合| 另类国产ts人妖高潮视频| 亚洲日本中文字幕| 欧美日韩一区不卡| 欧美亚洲免费电影| 91久久精品网| 久久久999成人| 日韩亚洲欧美综合| 国产日韩欧美一区二区三区在线观看| 久久久久久久激情视频| 99国产精品| 欧美成人免费网| 午夜欧美不卡精品aaaaa| 亚洲成人在线网站| 国产精品一二一区| 欧美人与性动交a欧美精品| 午夜欧美视频| 日韩一区二区免费高清| 欧美xx69| 久久久97精品| 午夜精品影院| 99精品国产高清一区二区| 国产日韩av在线播放| 欧美精品偷拍| 久久久人成影片一区二区三区观看 | 亚洲国产精品成人| 一本一本久久a久久精品综合妖精 一本一本久久a久久精品综合麻豆 | 亚洲久久在线| 免费在线亚洲| 久久久久久久久久久成人| 一本色道久久综合亚洲精品不卡| 国产一区二区三区黄视频| 欧美日韩精品一本二本三本| 久久久人成影片一区二区三区 | 乱人伦精品视频在线观看|