使用构造函数;像这样:
const wchar_t* const pStr1 = ...;
System::String^ const str1 = gcnew System::String(pStr1);
const char* const pStr2 = ...;
System::String^ const str2 = gcnew System::String(pStr2);
Run Code Online (Sandbox Code Playgroud)
如果您使用标准 C++ 字符串类(std::wstring或std::string),则可以通过该c_str()方法获取指针。你的代码可能是
const std::wstring const std_str1 = ...;
System::String^ const str1 = gcnew System::String(std_str1.c_str());
Run Code Online (Sandbox Code Playgroud)
请参阅System.String和此处的广泛讨论。