Home > Article > Backend Development > How to Convert a System::String to a std::string in C .NET?
In C .NET, converting a System::String to a std::string involves using the marshaling capabilities provided by the msclr namespace. Below are the steps to achieve this conversion:
Include the necessary headers:
<code class="cpp">#include "stdafx.h" #include <string> #include <msclr\marshal_cppstd.h></code>
Define the conversion:
<code class="cpp">auto& managedString = gcnew System::String("test"); msclr::interop::marshal_context context; auto& standardString = context.marshal_as<std::string>(managedString);</code>
With this approach, you can effectively convert a System::String to a std::string in C .NET. Alternatively, you can refer to the Microsoft documentation for additional conversion options.
The above is the detailed content of How to Convert a System::String to a std::string in C .NET?. For more information, please follow other related articles on the PHP Chinese website!