CString WriteString;
....
WriteString.Format("%s.%d d",WriteString,NI);
At above WriteString the
buffer too small warning is shown when executed any times because CString type
is not enough to hold string of any size.
My goal is to get content of WriteString to
write in to a file at end.
But it shows the warning when size of WriteString reach
to a limit. Is there any other way to write these strings to a file?or make the
WriteString be of unlimited size.
Solution 1:
In
the Format(..) context,
try to use the string as the receiver only
:
CString cszComposed(_T("SomeValue"));
...
CString cszTemp;
cszTemp.Format(_T(".%d d"), NI);
cszComposed += cszTemp;Solution 2:
WriteString.AppendFormat("%du.",NI,CPianoCtrl::NoteUporDwn);
This also works.
本文探讨了在使用CString类型进行字符串拼接时遇到的缓冲区过小警告问题,并提供了两种解决方案:一是通过字符串连接避免缓冲区溢出;二是直接使用CString的AppendFormat方法。

1万+

被折叠的 条评论
为什么被折叠?



