CString to char*

Started by
3 comments, last by Q-Parser 18 years, 9 months ago
Hi, sorry for that lame question, but is there any way how to convert CString to char* in VC++, except for copying characters from one string to another. Thanks
Advertisement
if you use std::string you can use str.c_str()
msdn
CString has a direct cast operator to "const char*" which should be enough for most uses. Note that you MUST not modify the data pointed to by CString.

Example:

CString cstrGnu( "20" );

int iValue = atoi( cstrGnu );


This would call the cast operator implicitely, you can also do so explicit:

wsprintf( szGnu, "Hello %s", (LPCTSTR)cstrGnu );

LPCTSTR is a define which maps to either const char* or const wchar_t* (depending on your projects unicode setting).

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Thanks a lot!

This topic is closed to new replies.

Advertisement