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

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>
            日韩午夜高潮| 亚洲曰本av电影| 欧美激情亚洲自拍| 欧美+亚洲+精品+三区| 欧美成人综合网站| 欧美日韩在线视频首页| 国产精品99免费看| 国产欧美一区二区精品仙草咪| 国产精品黄视频| 国产综合婷婷| 99精品视频免费在线观看| 亚洲尤物精选| 欧美电影免费| 中国女人久久久| 亚洲天堂男人| 久久久久久婷| 亚洲国产精品久久久久| 日韩视频久久| 久久久久久电影| 欧美日韩另类在线| 国产精品有限公司| 最新亚洲电影| 欧美在线观看一区二区三区| 欧美成人视屏| 性色一区二区三区| 欧美日韩一卡二卡| 亚洲青色在线| 美女视频黄免费的久久| 亚洲香蕉网站| 久久在线免费观看视频| 欧美中文字幕不卡| 免费看亚洲片| 国产乱肥老妇国产一区二| 亚洲激情视频在线| 久久精品国产综合| 妖精视频成人观看www| 久久尤物电影视频在线观看| 国产免费观看久久| 一区二区欧美激情| 欧美黄在线观看| 久久精品系列| 国产亚洲一级| 欧美在线观看视频在线| 亚洲一区二区三区乱码aⅴ蜜桃女| 欧美 日韩 国产一区二区在线视频 | 蜜臀a∨国产成人精品| 国产美女诱惑一区二区| 亚洲欧美日韩国产一区二区| 91久久精品一区二区别| 久久久在线视频| 一区二区亚洲| 免费黄网站欧美| 久久综合激情| 亚洲久久成人| 亚洲免费激情| 国产精品高精视频免费| 亚洲伊人一本大道中文字幕| 一区二区三区精品久久久| 欧美日韩视频在线观看一区二区三区 | 国产欧美日韩视频| 欧美日韩精品在线| 在线看无码的免费网站| 欧美成人一区二区三区在线观看 | 99在线|亚洲一区二区| 亚洲娇小video精品| 欧美国产精品v| 一区二区三区日韩精品| 99re6这里只有精品| 欧美午夜电影网| 欧美一区二区日韩一区二区| 午夜一区不卡| 国内精品亚洲| 亚洲欧洲在线播放| 欧美午夜视频| 久久久免费av| 噜噜噜91成人网| 99天天综合性| 亚洲欧美国产高清| 狠狠色综合播放一区二区| 欧美ab在线视频| 亚洲电影免费观看高清完整版| 麻豆成人小视频| 在线中文字幕日韩| 亚洲欧美视频在线| 亚洲丰满在线| 在线亚洲自拍| 伊人久久综合97精品| 亚洲精品日本| 黄色日韩在线| 亚洲午夜视频| 亚洲人成在线免费观看| 亚洲一区二区三区乱码aⅴ| 在线看一区二区| 亚洲欧美日韩一区二区三区在线观看 | 免费观看欧美在线视频的网站| 亚洲精品欧美极品| 欧美一级大片在线免费观看| 中文在线资源观看网站视频免费不卡 | 好吊色欧美一区二区三区四区| 久久精品免费| 欧美成人精品一区| 亚洲欧美国产三级| 久久综合九九| 欧美一区二粉嫩精品国产一线天| 欧美成人激情视频| 欧美在线日韩| 欧美日韩久久| 欧美激情区在线播放| 国产亚洲成人一区| 一区二区三区 在线观看视| 在线观看亚洲a| 亚洲一区二区免费看| 99在线|亚洲一区二区| 久久影院午夜论| 久久视频在线看| 国产裸体写真av一区二区| 日韩视频免费看| 日韩午夜中文字幕| 久热这里只精品99re8久| 久久黄色级2电影| 国产精品一区免费观看| 一本大道久久a久久精二百| 亚洲肉体裸体xxxx137| 久久免费视频网| 国产视频精品网| 亚洲作爱视频| 一区二区三区日韩欧美| 欧美福利视频一区| 欧美国产日韩一区二区三区| 一区在线播放视频| 久久久久久久性| 免费久久99精品国产自| 伊人久久噜噜噜躁狠狠躁| 欧美一区影院| 久久久久高清| 极品裸体白嫩激情啪啪国产精品| 欧美亚洲网站| 久久全球大尺度高清视频| 韩国一区二区三区在线观看 | 欧美精品二区| 亚洲国产黄色| 亚洲精品视频免费观看| 欧美激情国产日韩| 亚洲人精品午夜在线观看| 亚洲精品日韩综合观看成人91 | 亚洲激情成人在线| 亚洲精品系列| 欧美日韩天天操| 亚洲素人一区二区| 欧美一级理论性理论a| 国产一区二区毛片| 久久久久这里只有精品| 亚洲电影观看| 亚洲在线成人精品| 国产日韩欧美中文在线播放| 久久aⅴ国产欧美74aaa| 免费日韩一区二区| 亚洲欧洲精品一区二区三区波多野1战4| 米奇777超碰欧美日韩亚洲| 亚洲精品一区在线观看| 欧美亚洲一区二区在线观看| 极品尤物av久久免费看| 欧美大尺度在线| 亚洲尤物在线视频观看| 美日韩精品免费| 亚洲欧美激情四射在线日| 国产在线精品成人一区二区三区| 久久一区亚洲| 制服丝袜激情欧洲亚洲| 毛片av中文字幕一区二区| 99成人在线| 国产一区二三区| 欧美风情在线观看| 亚洲欧美一级二级三级| 亚洲第一精品夜夜躁人人躁| 午夜久久黄色| 亚洲激情午夜| 国内精品久久久久久| 欧美日韩精品伦理作品在线免费观看 | 亚洲国产精品一区二区第四页av| 欧美日韩国产电影| 久久国产日韩欧美| 亚洲蜜桃精久久久久久久| 久久久久在线| 亚洲一区观看| 亚洲精品视频在线| 国产三级精品三级| 欧美日韩综合在线免费观看| 久久综合狠狠综合久久激情| 亚洲欧美伊人| 99视频+国产日韩欧美| 欧美国产在线电影| 在线观看一区视频| 国产精品日韩一区二区三区| 免费成人你懂的| 久久精品一区二区三区不卡牛牛 | 免费中文日韩| 久久国产日韩欧美| 亚洲一区免费| 99精品热6080yy久久|