Sign in to follow this  

CString to char*

This topic is 4558 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

This topic is 4558 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this