什么是`CString`? [英] What is `CString`?

查看:115
本文介绍了什么是`CString`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我看到一些使用CStrings声明的代码不同.

Why do I see some code using CStrings declared differently.

有些使用这种格式

char a_c_string [];

其他人使用时

CString another_c_string;

有区别吗?我在CStrings上找到的所有引用都像在第一个示例中所做的那样声明了它,但我只看到它在论坛和诸如此类的例子之类的论坛上以其他方式完成了.

Is there a difference? All the references I have found on CStrings declare it as I did in the first example, I have only seen it done the other way on forums and the like where people are giving examples.

推荐答案

CString既不是C类型也不是C ++类型. 这似乎是微软的发明,实际上是一种替代方案到std::string:

CString is neither a C nor a C++ type. It appears to be a Microsoft invention that is essentially an alternative to std::string:

  • CString对象可能会由于串联操作而增长.
  • CString对象遵循值语义".将CString对象视为实际字符串,而不是指向字符串的指针.
  • 您可以自由地将CString对象替换为const char*LPCTSTR函数参数.
  • 转换运算符可以将字符串的字符作为只读字符数组(C样式的字符串)直接访问.
  • 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).

我建议忽略它,这样:

(a)人们知道您在说什么;
(b)您的代码是可移植的;
(c)您正在编写C ++,每个人都可以根据世界公认的ISO C ++标准进行合理化处理,因为很多人为此花费了很多很多时间来讨论这个明确的目的(是的,而不是像其他人那样一个公司办公室的房间).

(a) people know what you are talking about;
(b) your code is portable;
(c) you are writing C++ that everybody can rationalise about according to the worldwide-accepted ISO C++ standard that many, many people spend many, many hours arguing about for this express purpose (y'know, as opposed to a few guys in a room in one company's office).

仅当您使用 Microsoft Visual C ++ 进行编程时,此功能才可用,这是非常有限的.

It will only be available when you are programming with Microsoft Visual C++, which is substantially limiting.

这篇关于什么是`CString`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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