判断一个CString是否为空

用GetLength()<=0好,还是==""好?
CString str;
str += '\0';
int len = str.GetLength();
得到len=1;
但str=="", 返回的是true;
因为真正比较的时候只是单纯的逐个字符比较, '\0'作为结束符.
CString str2;
str==str2返回也是true, 因为str2被隐式转换为LPTCSTR, 比较也是一样的.
所以说应避免str += '\0'这样的写法.
在CString的使用过程中应该忘记'\0'的存在?
但声明一个char str[]; 必须memset(...)为0值,不然麻烦多.

结论:GetLength()<=0 好!

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-11-27
  • 2021-11-28
  • 2021-11-28
  • 2021-07-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
  • 2021-11-30
  • 2022-01-11
  • 2021-09-18
相关资源
相似解决方案