0

I have a standard library string, and I would like to make the following conversion:

System::String^ to std::string

Jacko
  • 12,665
  • 18
  • 75
  • 126
  • 2
    Possible duplicate of [C++/CLI Converting from System::String^ to std::string](https://stackoverflow.com/questions/946813/c-cli-converting-from-systemstring-to-stdstring) – Daniel A. White Jan 10 '19 at 00:51

1 Answers1

2

Code fragment to convert std::string to System::String^:

#include <msclr/marshal.h>

std::string str = "Hello World";
System::String^ result = msclr::interop::marshal_as<System::String^>(str.c_str());

Code fragment to convert System::String^ to std::string:

#include <msclr/marshal.h>

System::String^ str = "Hello World";
std::string result = msclr::interop::marshal_as<std::string>(str);
chronoxor
  • 3,159
  • 3
  • 20
  • 31