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

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| 性欧美暴力猛交另类hd| 欧美亚洲一区二区三区| 一区二区在线视频播放| 亚洲成人中文| 欧美午夜免费电影| 欧美在线中文字幕| 久久人体大胆视频| 99re热这里只有精品视频| 亚洲五月六月| 1024成人| 亚洲午夜日本在线观看| 好吊色欧美一区二区三区四区 | 亚洲另类一区二区| 在线视频亚洲| 在线播放视频一区| 一本久久综合亚洲鲁鲁| 激情综合网激情| av不卡免费看| 精久久久久久| 一区二区三区日韩在线观看| 国产亚洲人成网站在线观看| 亚洲国产成人不卡| 国产小视频国产精品| 亚洲国产欧美日韩精品| 国产精品综合av一区二区国产馆| 久久一日本道色综合久久| 欧美日韩少妇| 欧美激情一区二区三区在线视频观看 | 精品成人一区| 在线视频欧美一区| 亚洲黄网站在线观看| 亚洲欧美亚洲| 99在线热播精品免费99热| 欧美一级午夜免费电影| 一区二区激情视频| 久久夜色精品国产亚洲aⅴ| 亚洲欧美精品在线观看| 欧美激情按摩在线| 久久中文在线| 国产欧美精品一区aⅴ影院| 亚洲黄色小视频| 亚洲国产精品久久精品怡红院| 亚洲一区一卡| 亚洲亚洲精品三区日韩精品在线视频 | 欧美电影资源| 国产午夜精品美女视频明星a级| 亚洲黄色一区| 亚洲日本中文字幕| 美腿丝袜亚洲色图| 欧美成年视频| 亚洲国产mv| 久热精品视频在线观看| 久久一综合视频| 国内精品伊人久久久久av影院 | 欧美在线观看www| 午夜亚洲福利| 国产精品日韩精品欧美精品| 日韩视频在线免费| 宅男噜噜噜66一区二区| 欧美日韩国产精品| 亚洲美女在线看| 亚洲午夜精品一区二区| 欧美日韩国产一中文字不卡 | 欧美在线关看| 国产日韩一区二区三区在线| 午夜在线一区| 另类成人小视频在线| 国产免费亚洲高清| 久久精品国产欧美激情| 久久久国产精品一区| 国内自拍视频一区二区三区 | 欧美激情久久久| 日韩亚洲国产精品| 欧美天堂亚洲电影院在线观看 | 免播放器亚洲一区| 亚洲黄色在线看| 欧美日韩精品一本二本三本| 亚洲精品女av网站| 亚洲美女在线国产| 欧美精品福利在线| 一区二区三区精品视频在线观看| 亚洲欧美日韩在线一区| 国产日韩欧美一区二区三区四区| 欧美一区二区三区四区高清| 欧美成人按摩| 中文日韩在线视频| 国产午夜精品一区理论片飘花| 久久精品国产91精品亚洲| 欧美1级日本1级| 亚洲作爱视频| 国产在线精品成人一区二区三区| 久久一二三国产| 亚洲精品女人| 亚洲欧美视频在线观看| 好吊一区二区三区| 欧美日韩性视频在线| 欧美一区二区视频免费观看| 亚洲第一精品福利| 午夜精品久久一牛影视| 亚洲国产日韩一级| 国产精品日韩高清| 欧美电影免费观看| 欧美一区二区三区在线观看视频| 亚洲国产欧美另类丝袜| 欧美在线啊v| 一区二区三区.www| 在线成人www免费观看视频| 国产精品v欧美精品∨日韩| 久久在线免费观看视频| 亚洲免费影视第一页| 亚洲国产精品一区在线观看不卡| 久久aⅴ国产欧美74aaa| 99在线|亚洲一区二区| 狠狠色狠色综合曰曰| 国产精品成人一区二区三区夜夜夜| 久久久久久久成人| 亚洲综合色噜噜狠狠| 99热免费精品在线观看| 欧美激情一区二区三区成人| 久久精品首页| 性视频1819p久久| 亚洲视频在线一区观看| 亚洲精品日日夜夜| 亚洲国产清纯| 曰韩精品一区二区| 黄色成人在线网站| 国产真实久久| 国产日韩欧美精品综合| 国产精品入口尤物| 国产精品久久久久久久浪潮网站| 欧美另类一区| 欧美激情精品久久久| 女人色偷偷aa久久天堂| 久久久一区二区| 久久久久.com| 久久久免费精品| 久久在线免费观看| 欧美wwwwww| 欧美精品18videos性欧美| 欧美~级网站不卡| 欧美77777| 欧美另类在线播放| 欧美三级不卡| 国产精品免费一区豆花| 国产精品久久久久久户外露出 | 国产精品久久一区主播| 欧美视频一区二区三区…| 欧美日韩一区二区三区四区五区| 欧美日韩午夜视频在线观看| 欧美私人网站| 国产精品自拍网站| 红桃视频一区| 亚洲美女中出| 亚洲欧美另类中文字幕| 久久精选视频| 欧美激情欧美狂野欧美精品| 亚洲日产国产精品| 亚洲自拍16p| 亚洲人成在线播放网站岛国| 亚洲精品国产精品国自产观看| 亚洲精品中文字幕在线| 一区二区三区黄色| 午夜一级在线看亚洲| 美脚丝袜一区二区三区在线观看 | 亚洲成人资源网| 一区二区三区高清在线观看| 亚洲女性裸体视频| 久久久五月婷婷| 欧美日本免费一区二区三区| 国产精品私房写真福利视频 | 欧美精品免费观看二区| 国产精品porn| 在线看一区二区| 亚洲免费在线电影| 免费看的黄色欧美网站| 一本到高清视频免费精品| 欧美亚洲免费在线| 欧美精品久久久久久| 国产亚洲欧美一区| 一本到高清视频免费精品| 久久精品国语| 一本色道精品久久一区二区三区| 久久国产精品久久久久久电车| 欧美福利视频一区| 狠狠久久婷婷| 午夜视频在线观看一区二区三区| 欧美激情第10页| 午夜精品视频| 欧美日韩在线三区| 亚洲黄色性网站| 免费在线亚洲| 久久成人精品一区二区三区|