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

pqwbnv8z  于 2023-02-17  发布在  其他
关注(0)|答案(2)|浏览(258)

我有一个标准库字符串,我想进行以下转换:
系统::字符串^至标准::字符串

nafvub8i

nafvub8i1#

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

xytpbqjk2#

我可以确认这里@chronoxor所建议的一切对于我的旧控制台应用程序都能完美地工作,我用CppCLR for WinForms升级到了C++ GUI程序。该程序使用std::string来完成它的工作。我太懒了,没有改变它。

相关问题