问题:如何在 C++ MFC 中将 CString 转换为 const char * [英] Problem: How to convert CString into const char * in C++ MFC

查看:14
本文介绍了问题:如何在 C++ MFC 中将 CString 转换为 const char *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 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);

这篇关于问题:如何在 C++ MFC 中将 CString 转换为 const char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆