且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

问题:如何在C ++ MFC中将CString转换为const char *

更新时间:2023-11-14 19:56:52

CString直接转换为const char *

CString casts to const char * directly

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

将打印'foo'

版本的MFC也支持GetString()方法:

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

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