前言
當我們在開發c++/cli視窗程式時,會遇到需要把System::String^ 格式轉成std::string 或是相反的情況,在這邊紀錄一下
System::String^ to std::string
以下式轉換的程式碼:
std::string to System::String^
System::String^ to std::string
//Convert std::string to System::String^,os is std::string String^ str = gcnew String(os.c_str());
const char* chars = (const char*)(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(source)).ToPointer(); string dest = chars;
沒有留言:
張貼留言