如何解决需要不可靠的CString plus-operator的解决方法
void CLayoutLine::UnicodeStr(CGlobalStr &Str,LPCTSTR Sep) const
{
CString Line; // buffer for words in line
if (GetIndent())
{
// will be at least one tab
int tabs = ((GetIndent()-1) / GetVM()->ParaIndent()) + 1;
Line = CString(_T("\t"),tabs);
}
// add unsigned cast to eliminate warning - TBH 2017
for (int bb = 0; (unsigned) bb < m_Boxes.size(); bb++)
{
CString Word = m_Boxes[bb]->Unicodestr();
if (bb)
Line = Line + Sep;
Line = Line + Word;
}
Line = Line + Sep; // add separator in case of more text - TBH 3/2018
Str = Str + Line; // += is not reliable with strings - TBH 10/2020
}
有时,此代码工作可靠;有时不是。当我调试它时,我看到了以下内容:
在橙色框中执行代码行后,您可以看到Word的内容(绿色圆圈)为“消息”,但未附加到Line(红色圆圈)中! >
任何人都可以解释这种行为吗?还是这是Visual C ++ 2017中的错误?什么是最可靠的解决方法-直接使用Append()?还是我在CString + operator or Format中看到的Format()?我已经发现自己,CString的+ =运算符不可靠,如Different behaviour between CString operators “+=” and “+”
中所述更新
我尝试更改为Append()(Visual Studio建议它是CString的成员函数,但我没有记录在案),但是我得到了相同的行为。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。