Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem: How to convert CString into const char * in C++ MFC

How do I convert CString into const char *? I have tried everything found on the internet but I still cant convert them.

Please help.

Thank you.

like image 604
Chicko Bueno Avatar asked Oct 22 '25 02:10

Chicko Bueno


1 Answers

CString casts to const char * directly

CString temp;
temp = "Wow";
const char * foo = (LPCSTR) temp;
printf("%s", foo);

will print 'foo'

Newer version of MFC also support the GetString() method:

CString temp;
temp = "Wow";
const char * foo = temp.GetString();
printf("%s", foo);
like image 61
Gregor Brandt Avatar answered Oct 23 '25 18:10

Gregor Brandt