titleSingle.Format("%d%s%d%s%d",strNameNo+4,".",count0+1,".",single_No);
titleSingle.Format("%s %s%s%s%s%s",titleSingle,single_Names[1],".",single_Names[2],".",single_Names[3]);
以上方式会出现 buffer too small
Format在内部根据格式化参数列表会对字符串本身的内存空间进行重新分配,而如果直接采用字符串本身作为参数传入的话,这个过程中就会造成内存的冲突,而这个冲突是无法预见的,查看了下msdn,微软也作了相应的注释:
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变量
titleSingle1.Format("%d%s%d%s%d",strNameNo+4,".",count0+1,".",single_No);
titleSingle.Format("%s %s%s%s%s%s",titleSingle1,single_Names[1],".",single_Names[2],".",single_Names[3]);
参考: http://blog.csdn.net/zhulingfeng8726/article/details/7077341