Skip to main content
GameDev.net gamedev.net
🔒 Locked

CString to char*

Started by Q-Parser Jun 23, 2005 at 7:04 AM 3 replies 3.6k views
Original Post
Q-Parser
Q-Parser
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
Kalasjniekof
Kalasjniekof
if you use std::string you can use str.c_str()
doho
doho
msdn
Endurion
Endurion
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>
Q-Parser
Q-Parser
Thanks a lot!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.