stringc++-climanaged-c++

C++/CLI Converting from System::String^ to std::string


Can someone please post a simple code that would convert,

System::String^

To,

C++ std::string

I.e., I just want to assign the value of,

String^ originalString;

To,

std::string newString;

Solution

  • Check out System::Runtime::InteropServices::Marshal::StringToCoTaskMemUni() and its friends.

    Sorry can't post code now; I don't have VS on this machine to check it compiles before posting.