永发信息网

VC++6.0里,CString类如何和字符串相互转换?CString有重载操作符吗?

答案:1  悬赏:10  手机版
解决时间 2021-11-11 10:02
VC++6.0里,CString类如何和字符串相互转换?CString有重载操作符吗?
最佳答案
CString::operator
LPCTSTR

operator LPCTSTR ( ) const;

Return Value

A character pointer to the string’s data.

Remarks

This useful casting operator provides an efficient method to access the
null-terminated C string contained in a CString object. No characters are
copied; only a pointer is returned. Be careful with this operator. If you change
a CString object after you have obtained the character pointer, you may
cause a reallocation of memory that invalidates the pointer.

Example

The following example demonstrates the use of CString::operator
LPCSTR.
// If the prototype of a function is known to the compiler,
// the LPCTSTR cast operator may be invoked implicitly

CString strSports(_T("Hockey is Best!"));
TCHAR sz[1024];

lstrcpy(sz, strSports);

// If the prototype isn't known, or is a va_arg prototype,
// you must invoke the cast operator explicitly. For example,
// the va_arg part of a call to sprintf() needs the cast:

sprintf(sz, "I think that %s!\n", (LPCTSTR) strSports);

// while the format parameter is known to be an LPCTSTR and
// therefore doesn't need the cast:

sprintf(sz, strSports);

// Note that some situations are ambiguous. This line will
// put the address of the strSports object to stdout:

cout << strSports;

// while this line will put the content of the string out:

cout << (LPCTSTR) strSports;追问说中文
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
10KV负荷开关交接电流多少
有首诗里写的,分若莫上尘
尹师傅汽车电器修理在哪里啊,我有事要去这个
刚刚莫名其妙的进了一个扣扣群然后不停地抢红
华文黑体ttf原始大小,我看到有4MB.8MB的,但
为什么对自己女儿的老公叫姑爷
蚂蚁进家有什么寓意?
那里有初中地理学习视频?
好123星座运势怎么和以前不一样
公积金被原公司封存我该怎么办?
怎样当好学校播音员?
食故代表什么动物?
可以用两年的手机正常使用有什么推荐吗
一个数加上43,再减去43,结果是86,这个数是
山东淄博有几个区?
推荐资讯
脑控犯罪怎样报案,无证据怎么办,向哪个部门
下列CPU能插在LGA1155插槽中的是?
同时养两只猫咪会不会就不粘人了
万宝路香烟多少一包,美国红万宝
《你好!法语(1)》和《你好!法语(2)》只
三江南站在哪个地方
高姿这个品牌在国内卖的怎么样啊?
vlan里设ACL 时 in 和 out 方向是怎么控制
黄金正常加工损耗是多少
为什么我家汽车轮胎没有别人家的黑,呈浅黑,
地球上水储量大,有约多少的水集中在海洋
济南,同志MB该何去何从。
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?