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

2022-01-12 00:00:00 visual-c++ c++ mfc

如何将 CString 转换为 const char *?我已经尝试了在互联网上找到的所有内容,但我仍然无法转换它们.

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

请帮忙.

谢谢.

推荐答案

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);

相关文章