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

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 閱讀(4636) 評論(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>
            午夜精品久久久久久久久| 国产日韩视频一区二区三区| 欧美激情麻豆| 欧美中文日韩| 这里只有精品在线播放| 亚洲香蕉在线观看| 99视频精品全国免费| 国产噜噜噜噜噜久久久久久久久| 欧美日韩黄视频| 欧美激情久久久| 亚洲精品中文字| 一本色道久久综合亚洲精品婷婷| 亚洲自拍另类| 亚洲黄色在线看| 国产一区二区三区日韩欧美| 亚洲一区影音先锋| 亚洲国产日韩欧美在线图片| 国产精品扒开腿做爽爽爽软件| 亚洲精品孕妇| 国产一级一区二区| 在线亚洲精品| 亚洲欧美日韩成人| 亚洲一本大道在线| 亚洲高清123| 欧美成人按摩| 欧美一区二区三区精品| 久久婷婷综合激情| 亚洲成人在线观看视频| 樱花yy私人影院亚洲| 欧美先锋影音| 欧美在线观看你懂的| 一本大道久久a久久精二百| 久久久噜噜噜久久中文字幕色伊伊| 久久一区视频| 国产精品久久久久91| 国产一区久久| 亚洲精品免费一二三区| 久久精品在这里| 亚洲国产精品悠悠久久琪琪| 亚洲天堂久久| 欧美日韩精品在线观看| 国产亚洲一区二区三区| 日韩亚洲国产精品| 国产精品第十页| 亚洲少妇最新在线视频| 欧美日韩另类综合| 久久国产手机看片| 亚洲欧美日韩久久精品| 午夜精品久久久久久久99热浪潮| 久久激情视频久久| 99视频国产精品免费观看| 久久动漫亚洲| 亚洲特色特黄| 欧美小视频在线| 一本色道久久综合狠狠躁的推荐| 久久av一区二区三区亚洲| 亚洲成人在线网站| 久久婷婷国产综合精品青草 | 亚洲欧美国产制服动漫| 你懂的亚洲视频| 亚洲女同在线| 国产精品久99| 亚洲在线观看视频网站| 亚洲观看高清完整版在线观看| 久久久久久国产精品一区| 亚洲一区二区三区视频| 欧美日韩久久| 亚洲精品在线视频| 国产综合精品| 亚洲午夜在线观看| 91久久精品一区| 欧美另类99xxxxx| 亚洲国产欧美国产综合一区| 久久精品女人的天堂av| 欧美在线视频一区二区| 国产亚洲欧美一级| 欧美一区在线直播| 久久成人免费| 欧美视频精品一区| 一区二区电影免费观看| 一区二区三区 在线观看视| 欧美成人一区二区三区片免费| 久久精品国产综合| 精品91在线| 欧美国产综合一区二区| 久久久精品999| 亚洲全黄一级网站| 亚洲国产精品久久精品怡红院 | 夜夜嗨av一区二区三区四季av| 欧美xxx成人| 妖精成人www高清在线观看| 亚洲精品国精品久久99热一 | 国产一区自拍视频| 久久婷婷蜜乳一本欲蜜臀| 久久先锋资源| 亚洲视频你懂的| 久久爱www| 亚洲人成人一区二区三区| 亚洲精品中文字幕有码专区| 国产精品日日做人人爱| 久久精品一区二区三区中文字幕| 毛片一区二区三区| 亚洲一区在线免费观看| 欧美一区日本一区韩国一区| 欧美激情一区二区| 午夜亚洲福利| 国产视频一区在线| 亚洲国产日韩欧美综合久久| 亚洲无限乱码一二三四麻| 国产日韩欧美麻豆| 欧美成人官网二区| 亚洲视频免费看| 亚洲自拍电影| 日韩午夜激情电影| 欧美一区二区在线播放| 99精品视频网| 欧美在线首页| 亚洲天堂网在线观看| 久久成人在线| 亚洲图片自拍偷拍| 麻豆av福利av久久av| 亚洲一区免费看| 久久久www成人免费无遮挡大片 | 亚洲伦理在线| 久久精品72免费观看| 一区二区三区欧美成人| 久久国产精品99精品国产| 欧美日韩国产成人| 欧美在线视频在线播放完整版免费观看| 久久精品国产第一区二区三区| 国产精品99久久99久久久二8 | 欧美精品在线观看一区二区| 久久久噜噜噜久噜久久| 欧美三区视频| 亚洲午夜羞羞片| 国产精品99久久久久久人| 欧美在线免费观看视频| 欧美午夜宅男影院在线观看| 久久精品国产亚洲aⅴ| 欧美精品在线网站| 女女同性女同一区二区三区91| 国产精品网站一区| 亚洲日本欧美| 91久久国产综合久久| 久久精选视频| 麻豆成人在线播放| 国内在线观看一区二区三区| 午夜久久美女| 亚洲主播在线播放| 欧美日韩伦理在线免费| 99视频一区二区三区| 日韩视频三区| 欧美日本一区二区视频在线观看| 亚洲欧洲日本在线| 亚洲国产精品悠悠久久琪琪| 久久久7777| 欧美黄色小视频| 亚洲天堂激情| 国产精品视频一二| 亚欧成人在线| 亚洲高清成人| 一区二区福利| 国产免费成人在线视频| 午夜国产精品视频| 久久天天躁夜夜躁狠狠躁2022 | 久久久久久黄| 亚洲激情一区二区| 午夜久久久久| 亚洲国产va精品久久久不卡综合| 久久一区二区三区av| 亚洲精品一区中文| 欧美一乱一性一交一视频| 伊人婷婷久久| 国产精品白丝黑袜喷水久久久| 欧美亚洲系列| 亚洲日本成人女熟在线观看| 午夜精品久久久久久99热软件| 国产专区欧美精品| 欧美理论大片| 性做久久久久久久免费看| 蜜臀久久久99精品久久久久久| 亚洲少妇中出一区| 久久国产日本精品| 亚洲国产精品一区二区www在线| 亚洲欧美国产三级| 亚洲黄色高清| 国产在线欧美日韩| 欧美视频在线视频| 久久最新视频| 香蕉久久夜色精品国产使用方法| 亚洲国产网站| 免费av成人在线| 欧美影院午夜播放| 99在线视频精品| 亚洲国产经典视频| 国产一区二区三区四区五区美女| 欧美日韩久久不卡| 久久久久久一区二区三区| 一本色道久久综合狠狠躁篇怎么玩 | 亚洲免费观看高清完整版在线观看|