首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VC >

System:String 转 std上的string

2012-12-27 
System::String 转 std下的stringSystem::String 转 std下的stringString* str ddstring str2

System::String 转 std下的string
System::String 转 std下的string
String* str = "dd";
string str2 = "";
如何把str中的"dd"赋值到str2中??
[解决办法]
String* str = "dd";
string str2 = reinterpret_cast<char*>(System::Runtime::InteropServices::Marshal::StringToCoTaskMemAnsi(str).ToPointer());
[解决办法]


std::string ConvertToString(System::String^ str)
{
 int q=(int)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str);
 char* p=(char*)q;
 return std::string(p);
}

热点排行