[英]How can I check if a MFC CString is null?
A CString
object is never NULL
. CString
对象从不为NULL
。 Unlike a char*
or wchar*
, which can be NULL
, the internal buffer of a CString
object which is a pointer always points to a data. 与
char*
或wchar*
(可以为NULL
,作为指针的CString
对象的内部缓冲区始终指向数据。 For a given CString
object, you can only differentiate whether it is empty or not using CString::IsEmpty()
. 对于给定的
CString
对象,只能使用CString::IsEmpty()
区分它是否为空。
For the same reason, the LPCTSTR
cast operator never returns NULL
. 出于相同的原因,
LPCTSTR
运算符从不返回NULL
。
Due to the internal layout of the CString
class template 1) , the pointer stored cannot ever be NULL
. 由于
CString
类模板1)的内部布局,因此存储的指针永远不能为NULL
。
The CString
class template has a single class member: m_pszData
. CString
类模板具有一个类成员: m_pszData
。 This member not only contains the string data, but also additional information (like string length, reference count, buffer capacity, etc.; see CStringData ). 该成员不仅包含字符串数据,还包含其他信息(例如字符串长度,引用计数,缓冲区容量等;请参见CStringData )。 This additional information is stored to the left of the stored pointer.
此附加信息存储在存储的指针的左侧。 Both parts (string data and character buffer) must be allocated in a single block of memory, as there is only one pointer to reference both.
这两个部分(字符串数据和字符缓冲区)都必须分配在一个内存块中,因为只有一个指针可以引用这两个部分。 Since the string data always needs to be there, the
m_pszData
can never be NULL
. 由于字符串数据始终需要存在,因此
m_pszData
永远不能为NULL
。
CString
is a typedef for a particular CStringT
template instantiation.
CString
是用于特定CStringT
模板实例化的typedef。
The CStringT
itself is derived from the CSimpleStringT
class template.
CStringT
本身是从CSimpleStringT
类模板派生的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.