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());
------解决方案--------------------------------------------------------
- C/C++ code
std::string ConvertToString(System::String^ str){ int q=(int)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str); char* p=(char*)q; return std::string(p);}