T Tim Mulholland Sep 15, 2003 #1 How can i (using Managed C++) convert a System::String object containing basic text into a char* object? Thanks in advance, Tim
How can i (using Managed C++) convert a System::String object containing basic text into a char* object? Thanks in advance, Tim
N Nishant S Sep 15, 2003 #2 Here's one way :- String* s1 = S"............"; const __wchar_t __pin* pstr = PtrToStringChars(s1);
S Sin Sep 15, 2003 #3 Here's one way :- String* s1 = S"............"; const __wchar_t __pin* pstr = PtrToStringChars(s1); Click to expand... I think he meant a char*, as in single byte char*... Here's one way : String foo= "Hello"; IntPtr ptr = Marshal::StringToCoTaskMemAnsi(foo); char *singleByteFoo= (char*)ptr.ToPointer(); // do stuff with singleByteFoo Marshal::FreeCoTaskMem(ptr); // here, singleByteFoo is not valid anymore Alex.
Here's one way :- String* s1 = S"............"; const __wchar_t __pin* pstr = PtrToStringChars(s1); Click to expand... I think he meant a char*, as in single byte char*... Here's one way : String foo= "Hello"; IntPtr ptr = Marshal::StringToCoTaskMemAnsi(foo); char *singleByteFoo= (char*)ptr.ToPointer(); // do stuff with singleByteFoo Marshal::FreeCoTaskMem(ptr); // here, singleByteFoo is not valid anymore Alex.