有关CString的疑问

itelly 2012-03-02 10:16:40
CString 是以null结尾的指针吗?和LPCTSTR是一样?
如果不是那么
CString strText=_T("application");
SetWindowText(strText);
为什么会成功执行?
它的原型是void SetWindowText( LPCTSTR lpszString );LPCTSTR不是一个指针吗?
...全文
104 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
itelly 2012-03-02
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ouyh12345 的回复:]

LPCTSTR是指向字符串的指针
CString是一个类,包含了字符串
CString strText=_T("application");
SetWindowText(strText);
会把字符串成员取出来,并转换
[/Quote]
我在msdn里面发现了这句话
CString provides the operator LPCTSTR to convert between CString and LPCTSTR
疯狂-的-蜗牛 2012-03-02
  • 打赏
  • 举报
回复
CString是MFC里面为处理字符串而实现的一个类
如果不会用也可以选择标准C++里面string啊
都很强大的
shn521 2012-03-02
  • 打赏
  • 举报
回复
CString objects also have the following characteristics:

CString objects can grow as a result of concatenation operations.


CString objects follow “value semantics.” Think of a CString object as an actual string, not as a pointer to a string.


You can freely substitute CString objects for const char* and LPCTSTR function arguments.


A conversion operator gives direct access to the string’s characters as a read-only array of characters (a C-style string).
Tip Where possible, allocate CString objects on the frame rather than on the heap. This saves memory and simplifies parameter passing.
shn521 2012-03-02
  • 打赏
  • 举报
回复
额,我试了下,我这里编译通过
ouyh12345 2012-03-02
  • 打赏
  • 举报
回复
LPCTSTR是指向字符串的指针
CString是一个类,包含了字符串
CString strText=_T("application");
SetWindowText(strText);
会把字符串成员取出来,并转换
shn521 2012-03-02
  • 打赏
  • 举报
回复
CString strText
strText 是CString类的对象,不是指针
gold_water 2012-03-02
  • 打赏
  • 举报
回复
CString是一个类, 封装了对字符串常用的操作,重载了N个操作符,实现了对几种类型之间的转换.
lgstudyvc 2012-03-02
  • 打赏
  • 举报
回复
不知道你为啥必须要用string
CString不能解决,
感觉那样容易用乱
itelly 2012-03-02
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 gameslq 的回复:]

不行啊,用string的话老是提示
C:\Program Files\Microsoft Visual Studio\MyProjects\Demo1_10\Demo1_10Dlg.cpp(189) : error C2065: 'string' : undeclared identifier

包含#include <string>
然后
std::string s;
[/Quote]
谢谢.
gameslq 2012-03-02
  • 打赏
  • 举报
回复
不行啊,用string的话老是提示
C:\Program Files\Microsoft Visual Studio\MyProjects\Demo1_10\Demo1_10Dlg.cpp(189) : error C2065: 'string' : undeclared identifier

包含#include <string>
然后
std::string s;
itelly 2012-03-02
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 mfcing 的回复:]

CString是MFC里面为处理字符串而实现的一个类
如果不会用也可以选择标准C++里面string啊
都很强大的
[/Quote]
不行啊,用string的话老是提示
C:\Program Files\Microsoft Visual Studio\MyProjects\Demo1_10\Demo1_10Dlg.cpp(189) : error C2065: 'string' : undeclared identifier

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧