To convert from a system::String to an std::string, I use the following code:
IntPtr p = Marshal::StringToHGlobalAnsi(PORT);
string newString = static_cast<char*>(p.ToPointer());
Marshal::FreeHGlobal(p);
However, the place where I got the code uses
IntPtr p = Marshal::StringToHGlobalAnsi(PORT);
char* newString = static_cast<char*>(p.ToPointer());
Marshal::FreeHGlobal(p);
For some reason though, I get garbage in newString if I do the char* version. Anyone know why this would happen?
Thanks.