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

时间:2019-01-10 00:48:19

标签: c++ managed-c++

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

System :: String ^到std :: string

1 个答案:

答案 0 :(得分:1)

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);