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

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>
            亚洲人成7777| 亚洲国产一成人久久精品| 亚洲欧美在线播放| 亚洲欧美日韩国产精品| 亚洲素人在线| 亚洲永久免费观看| 99热这里只有精品8| 99这里只有精品| 亚洲免费影视第一页| 欧美伊久线香蕉线新在线| 久久aⅴ国产欧美74aaa| 久久人人97超碰人人澡爱香蕉| 欧美91福利在线观看| 欧美日本精品在线| 久久精品卡一| 欧美精品一区二区三区视频| 欧美日韩妖精视频| 国产热re99久久6国产精品| 好吊一区二区三区| 日韩视频永久免费| 欧美一区二区三区四区在线观看| 另类图片国产| 99在线|亚洲一区二区| 久久精品二区三区| 欧美日韩免费视频| 亚洲第一区在线观看| 亚洲欧美激情一区| 亚洲福利视频三区| 尤物在线精品| 亚洲黄色一区| 久久久久久久波多野高潮日日| 亚洲高清网站| 午夜亚洲激情| 欧美日韩视频一区二区| 精品电影在线观看| 亚洲免费中文| 亚洲经典一区| 欧美在线免费视屏| 国产精品久久久久久福利一牛影视 | 国产午夜精品久久久久久免费视| 亚洲国产专区校园欧美| 欧美在线视频免费观看| 亚洲人精品午夜| 久久免费偷拍视频| 国产区亚洲区欧美区| 亚洲一级高清| 亚洲精品久久久久中文字幕欢迎你 | 国内一区二区三区在线视频| a91a精品视频在线观看| 女生裸体视频一区二区三区| 午夜一区不卡| 国产欧美日韩三区| 午夜精品久久久久久久99水蜜桃 | 久久久久国产精品一区二区| 国产精品www.| 中文亚洲免费| 亚洲精品日韩在线观看| 欧美大片免费观看在线观看网站推荐| 伊人春色精品| 另类尿喷潮videofree| 久久大逼视频| 国内视频精品| 麻豆av福利av久久av| 久久久国产91| 亚洲丶国产丶欧美一区二区三区| 蜜桃av一区二区| 久久视频在线看| 亚洲国产欧美日韩精品| 欧美激情亚洲激情| 欧美日韩麻豆| 亚洲欧美日韩国产中文在线| 亚洲中无吗在线| 国产精品一二一区| 久久久精品动漫| 久久久久久久一区二区| 亚洲国产女人aaa毛片在线| 欧美成人蜜桃| 欧美日韩在线亚洲一区蜜芽| 午夜视频在线观看一区| 久久国产日韩欧美| 91久久黄色| 正在播放欧美视频| 国产日韩欧美麻豆| 免费黄网站欧美| 欧美精品一区二区三区一线天视频| 99视频国产精品免费观看| 宅男在线国产精品| 樱花yy私人影院亚洲| 亚洲精品免费在线观看| 国产精品手机在线| 欧美不卡一卡二卡免费版| 欧美黄色日本| 欧美一区二区三区免费观看| 久久久久久久久久看片| 亚洲精品欧美一区二区三区| 在线视频日韩精品| 136国产福利精品导航| 日韩午夜av| 一区二区视频在线观看| 日韩亚洲欧美一区二区三区| 国产在线不卡精品| 日韩视频一区二区三区| 亚洲第一二三四五区| 99re6热只有精品免费观看| 国模大胆一区二区三区| 日韩系列在线| 亚洲国产另类久久精品| 亚洲欧美成人精品| 99热在线精品观看| 久久久在线视频| 欧美一区二区三区电影在线观看| 欧美精品成人91久久久久久久| 久久精品免费看| 国产精品成人一区二区网站软件| 欧美成人免费网| 国产亚洲成精品久久| 亚洲精品一区二区网址 | 亚洲最新中文字幕| 国产小视频国产精品| 亚洲美女网站| 在线精品在线| 欧美一区二区精品| 午夜精品久久久久久久蜜桃app | 一区二区日韩免费看| 久久久久久久一区| 久久av红桃一区二区小说| 欧美三级韩国三级日本三斤| 亚洲成人在线视频网站| 狠狠狠色丁香婷婷综合久久五月 | 欧美日韩精品欧美日韩精品一 | 在线亚洲精品| 一区二区毛片| 欧美人在线观看| 91久久精品一区二区别| 亚洲经典自拍| 欧美α欧美αv大片| 欧美国产一区二区| 亚洲福利一区| 嫩草影视亚洲| 91久久综合亚洲鲁鲁五月天| 亚洲精品三级| 欧美日韩ab| 夜夜嗨av一区二区三区免费区| 日韩亚洲欧美在线观看| 欧美精品一区在线发布| 亚洲高清资源综合久久精品| 亚洲激情在线视频| 欧美精品一区二区三区蜜桃| 日韩视频在线观看国产| 羞羞漫画18久久大片| 国产视频丨精品|在线观看| 欧美影院午夜播放| 免费欧美日韩国产三级电影| 亚洲国产精品一区二区www| 欧美 日韩 国产 一区| 91久久久亚洲精品| 午夜精品久久久久久久久久久久| 国产亚洲一区二区精品| 久久人91精品久久久久久不卡| 亚洲成色精品| 亚洲伊人网站| 狠狠v欧美v日韩v亚洲ⅴ| 免费在线国产精品| 一片黄亚洲嫩模| 久久蜜臀精品av| 99精品国产在热久久婷婷| 国产精品男人爽免费视频1| 欧美在线视频在线播放完整版免费观看 | 国产精品福利影院| 亚洲激情二区| 一本色道**综合亚洲精品蜜桃冫| 正在播放欧美一区| 国产婷婷精品| 欧美高清视频在线播放| 在线中文字幕日韩| 久久躁狠狠躁夜夜爽| 一本一道久久综合狠狠老精东影业 | 亚洲欧美网站| 亚洲成色www8888| 久久成人免费日本黄色| 亚洲欧洲一区二区三区久久| 国产精品久久网站| 欧美国产免费| 久久久91精品国产| 99pao成人国产永久免费视频| 久久综合网色—综合色88| 亚洲亚洲精品在线观看| 亚洲国产一区二区精品专区| 国产美女一区| 欧美视频在线一区| 欧美成人免费网站| 久久久久一区二区三区| 午夜精品成人在线| 一区二区三区四区五区精品| 欧美福利电影在线观看| 久久久天天操| 久久国产成人| 欧美一区二区视频在线观看2020| 一本一道久久综合狠狠老精东影业 | 欧美国产一区在线|