从 System::String^ 转换为 System::String

Convert from System::String^ to System::String

我有一个标准库字符串,我想进行如下转换:

System::String^ 到 std::string

std::string转换为System::String^的代码片段:

#include <msclr/marshal.h>

std::string str = "Hello World";
System::String^ result = msclr::interop::marshal_as<System::String^>(str.c_str());

System::String^转换为std::string的代码片段:

#include <msclr/marshal.h>

System::String^ str = "Hello World";
std::string result = msclr::interop::marshal_as<std::string>(str);