views:

436

answers:

1

I saw another post that suggested the following:

String^ clistr = gcnew String("sample");
IntPtr p = Marshal::StringToHGlobalAnsi(clistr);
char *pNewCharStr = static_cast<char*>(p.ToPointer());
Marshal::FreeHGlobal(p);

I just wanted to check and see if there is any other, preferred way, or if anything was wrong with the above?

+3  A: 

The first result on google for "System::String char*" seems to offer pretty comprehensive guidance. http://support.microsoft.com/kb/311259

kdt