C++/CLI String Conversions

后端 未结 2 1726
迷失自我
迷失自我 2020-12-18 14:01

I found this really nice piece of code that converts a string to a System:String^ as in:

System::String^ rtn = gcnew String(move.c_str());  // \         


        
2条回答
  •  -上瘾入骨i
    2020-12-18 14:34

    this could be useful:

    wchar_t *str = "Hi StackOverflow"; //native
    String^ mstr= Marshal::PtrToStringAnsi((IntPtr)str); // native to safe managed
    wchar_t* A=( wchar_t* )Marshal::StringToHGlobalAnsi(mstr).ToPointer(); // return back to native 
    

    don't forget using namespace System::Runtime::InteropServices;

提交回复
热议问题