我有一个标准库字符串,我想进行以下转换:系统::字符串^至标准::字符串
nafvub8i1#
将std::string转换为System::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);
xytpbqjk2#
我可以确认这里@chronoxor所建议的一切对于我的旧控制台应用程序都能完美地工作,我用CppCLR for WinForms升级到了C++ GUI程序。该程序使用std::string来完成它的工作。我太懒了,没有改变它。
2条答案
按热度按时间nafvub8i1#
将
std::string
转换为System::String^
的代码片段:将
System::String^
转换为std::string
的代码片段:xytpbqjk2#
我可以确认这里@chronoxor所建议的一切对于我的旧控制台应用程序都能完美地工作,我用CppCLR for WinForms升级到了C++ GUI程序。该程序使用std::string来完成它的工作。我太懒了,没有改变它。