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

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>
            亚洲人体偷拍| 欧美日韩亚洲一区二区| 国产午夜精品麻豆| 亚洲欧美精品伊人久久| 久久er精品视频| 国产欧美大片| 蜜臀久久久99精品久久久久久| 免费视频一区| 亚洲一区久久| 国内精品久久久久久久影视蜜臀 | 日韩视频在线一区二区| 欧美日韩视频在线一区二区观看视频| 在线视频亚洲欧美| 久久噜噜亚洲综合| 中国亚洲黄色| 精品1区2区| 欧美性色综合| 免费毛片一区二区三区久久久| 亚洲片在线观看| 欧美在线视频观看| 夜夜嗨av一区二区三区中文字幕| 国产精品九九| 亚洲欧美日韩久久精品| 欧美一区二区视频免费观看 | 国产精品视频午夜| 免费的成人av| 亚洲欧美国产不卡| 亚洲激情在线| 免费不卡中文字幕视频| 亚洲男女自偷自拍| 91久久精品国产91性色| 国产精品日韩在线观看| 欧美韩国日本综合| 久久激情视频| 一级日韩一区在线观看| 欧美国产一区二区在线观看| 午夜精品久久久久久久99樱桃| 亚洲精品一区二区三区蜜桃久| 国产欧美日本一区视频| 欧美日韩国产美| 欧美国产日韩一二三区| 久久米奇亚洲| 久久精品国产一区二区三| 亚洲图片自拍偷拍| 亚洲青色在线| 亚洲日韩欧美视频一区| 亚洲国产婷婷香蕉久久久久久99| 可以看av的网站久久看| 久久精品91| 久久精品99国产精品酒店日本| 亚洲自拍偷拍网址| 亚洲一区二区免费视频| 在线亚洲观看| 一区二区电影免费观看| 亚洲精品影视在线观看| 亚洲老板91色精品久久| 亚洲免费观看高清完整版在线观看熊 | 欧美18av| 欧美精品在线视频观看| 欧美日韩喷水| 欧美日韩亚洲一区二区三区| 欧美日韩一区国产| 国产精品久久久久久久第一福利 | 国产日韩欧美中文| 激情小说另类小说亚洲欧美 | 99riav久久精品riav| 亚洲日本电影在线| 一本一本a久久| 亚洲香蕉视频| 午夜精品福利视频| 久久亚洲精品欧美| 欧美成人一区二区三区| 亚洲国产裸拍裸体视频在线观看乱了| 亚洲国产高清视频| 亚洲午夜电影| 久久嫩草精品久久久久| 欧美大片免费观看在线观看网站推荐| 欧美人成免费网站| 国产欧美欧美| 亚洲另类黄色| 久久久久久久999| 亚洲日本电影| 午夜在线电影亚洲一区| 美女视频黄免费的久久| 欧美日韩一级黄| 国产一区二区成人| 99视频精品全部免费在线| 欧美一区二区大片| 欧美黑人多人双交| 亚洲一区自拍| 欧美不卡在线视频| 国产美女诱惑一区二区| 亚洲激情另类| 久久国产精品电影| 亚洲精品日韩在线| 久久精品国产亚洲精品| 欧美日本在线观看| 激情久久中文字幕| 亚洲免费在线看| 欧美福利网址| 先锋影音国产精品| 欧美日韩美女在线观看| 激情欧美一区| 久久精品官网| 亚洲小说春色综合另类电影| 蜜臀久久99精品久久久画质超高清 | 性欧美大战久久久久久久久| 欧美日韩成人综合天天影院| 狠狠爱www人成狠狠爱综合网| 亚洲视频久久| 亚洲东热激情| 欧美在线播放一区| 国产精品久久久久aaaa| 亚洲精选视频在线| 免费日韩成人| 久久野战av| 在线观看国产精品淫| 久久精品夜色噜噜亚洲a∨| 亚洲在线国产日韩欧美| 亚洲人成人一区二区三区| 六月丁香综合| 在线精品福利| 欧美sm极限捆绑bd| 久久在线免费观看| 精品成人在线视频| 麻豆av一区二区三区| 欧美中文字幕不卡| 国产主播一区二区三区四区| 欧美一级在线视频| 午夜精品久久99蜜桃的功能介绍| 国产精品h在线观看| 亚洲网站在线播放| 中日韩午夜理伦电影免费| 欧美日韩一区综合| 亚洲永久精品国产| 亚洲一区二区视频| 国产情人综合久久777777| 性欧美长视频| 亚洲欧美日韩一区二区| 国产一区二区成人久久免费影院| 久久久久成人网| 久久在精品线影院精品国产| 亚洲欧洲精品一区二区三区不卡 | 欧美日韩精品欧美日韩精品| 亚洲精品欧美日韩专区| 日韩视频第一页| 欧美午夜免费电影| 久久精品男女| 久久影院午夜论| 一区二区三区精品在线| 亚洲一区二区在线观看视频| 国产性天天综合网| 欧美高清视频一区| 欧美日韩一区二区三区免费| 亚洲欧美在线x视频| 欧美一区二区大片| 伊人蜜桃色噜噜激情综合| 91久久在线观看| 国产精品久久久久aaaa| 免费h精品视频在线播放| 欧美日韩精品在线视频| 午夜精品久久久久久久| 久久综合久久综合九色| 亚洲淫片在线视频| 久久漫画官网| 亚洲综合不卡| 麻豆精品传媒视频| 欧美一区二区久久久| 毛片基地黄久久久久久天堂| 亚洲一区二区视频在线| 欧美伊久线香蕉线新在线| 亚洲美女黄网| 欧美一区二区精品在线| 亚洲精品在线免费观看视频| 亚洲欧美卡通另类91av | 国产综合网站| 欧美伊人久久久久久午夜久久久久| 性视频1819p久久| 在线视频中文亚洲| 久久久久久伊人| 午夜精品国产精品大乳美女| 看欧美日韩国产| 欧美主播一区二区三区美女 久久精品人| 久久综合五月| 久久亚洲春色中文字幕| 国产精品久久久久久av福利软件| 欧美成黄导航| 国产亚洲精品综合一区91| 一本一本久久a久久精品综合麻豆| 亚洲二区精品| 久久不见久久见免费视频1| 中日韩高清电影网| 欧美精品亚洲精品| 欧美高清视频在线播放| 黄色av一区| 欧美一区二区三区日韩| 欧美一区激情| 国产精品日韩一区| 亚洲一本大道在线| 亚洲午夜精品一区二区|