469,282 Members | 2,120 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Convert System::String to char*

How can i (using Managed C++) convert a System::String object containing
basic text into a char* object?

Thanks in advance,

Tim
Nov 16 '05 #1
3 5864
Here's one way :-

String* s1 = S"............";
const __wchar_t __pin* pstr = PtrToStringChars(s1);

--
Regards,
Nish [VC++ MVP]

"Tim Mulholland" <ti*@eyeresponse.com> wrote in message
news:#F**************@TK2MSFTNGP09.phx.gbl...
How can i (using Managed C++) convert a System::String object containing
basic text into a char* object?

Thanks in advance,

Tim

Nov 16 '05 #2
Sin
> Here's one way :-

String* s1 = S"............";
const __wchar_t __pin* pstr = PtrToStringChars(s1);


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.
Nov 16 '05 #3
My bad! :-(

--
Regards,
Nish [VC++ MVP]

"Sin" <br****@hotmail.com> wrote in message
news:uG**************@TK2MSFTNGP10.phx.gbl...
I think he meant a char*, as in single byte char*... Here's one way :

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Yifan | last post: by
2 posts views Thread by Alper Akcayoz | last post: by
3 posts views Thread by Maileen | last post: by
7 posts views Thread by nicolas.hilaire | last post: by
1 post views Thread by AJ32 | last post: by
12 posts views Thread by Peter | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.