471,616 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,616 software developers and data experts.

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 5921
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
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.