错误:
VC程序运行时提示下图的错误,但并不是每次都提示。
解决:
The call will fail if the string object itself is offered as a parameter to Format. For example, the following code:
CString str = "Some Data";
str.Format("%d%d", str, 123); //Attention: str is also used in the parameter list.
will cause unpredictable results.
为了避免这种无法预见的问题,最好不要采取将字符串本身作为参数作为Format的参数,可以另外定义一个CString变量:
cstring str,strTmp;
strTmp="asd....";
str.format("%s",strTmp);
这样问题就解决了。
本文介绍了解决VC程序中使用CString与Format方法时出现的不可预知错误的方法。通过避免将同一个字符串对象同时用作Format方法的参数,可以有效避免此类问题。建议创建额外的CString变量来传递。
2万+

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



