从std :: string转换为String ^

问题描述 投票:3回答:2

我在C ++中有一个函数,其值在std :: string类型中,并且想要将其转换为String ^。

void(String ^outValue)
{
   std::string str("Hello World");
   outValue = str;
}
c++ string c++-cli managed-c++
2个回答
7
投票
// marshal_as_test.cpp // compile with: /clr #include <stdlib.h> #include <string> #include <msclr\marshal_cppstd.h> using namespace System; using namespace msclr::interop; int main() { std::string message = "Test String to Marshal"; String^ result; result = marshal_as<String^>( message ); return 0; }

另请参见Overview of Marshaling


6
投票
#include <string> #include <iostream> using namespace System; using namespace std; int main() { string str = "test"; String^ newSystemString = gcnew String(str.c_str()); }

http://msdn.microsoft.com/en-us/library/ms235219.aspx

© www.soinside.com 2019 - 2024. All rights reserved.