When I first started working with forms in Microsoft Visual Studio I had some problems getting to grips with their managed class. One of the more fustrating points was that text boxes returned text as type System::String and all my functions were expecting std::strings.
Converting from std:string to System::String was quite simple:
Code:
std::string myString = "Hello World" | |
| |
System::String out = gcnew System::String(myString.c_str()); |
However, converting System::String to std::string was a little more tricky:
Code:
System::String myString = "Hello World"; | |
| |
std::string out = (const char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(myString )).ToPointer(); |