0
点赞
收藏
分享

微信扫一扫

[C++CLI][原创]CLI的^string与MFC的CString转换


1:std::string转String^:
std::string stdstr="";
String^ str = marshal_as<String^>(stdstr);


2:String^转std::string:
String^ str= gcnew String();
std::string stdstr = marshal_as<std::string>(str->ToString());


3:CString转Sting^:
CString cstr="";
String^ str = marshal_as<String^>(cstr.GetBuffer());
cstr.ReleaseBuffer();


4:String^转CString:
String^ str;
CString cstr(str);

记得选择公共语言运行时支持(/clr)和引用using namespace System;
具体实例:
System::String ^str = "hello world";
CString msg(str);
MessageBox(msg); 

举报

相关推荐

0 条评论