CString to char*
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
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).
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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement