VC.NET中有关CString.Format()的奇怪问题???
int temp;
CString str;
str.Format( "%d ",temp);
编译出错,提示说:
error C2664: “void ATL::CStringT <BaseType,StringTraits> ::Format(const wchar_t *,...)”: 不能将参数 1 从“const char [3]”转换为“const wchar_t *”
编译环境: VC.NET 2005
[解决办法]
str.Format(_T( "%d "),temp);
[解决办法]
因为VC.NET项目的字符集默认为 UNICODE,于是项目里的所有字符串都是宽字符串,而文字量还是char。所以文字量要用_T括起来。
我也刚用VC2005,感觉很奇怪的是默认项目里CString是ATL的模板实现,而是在VC6里的CString作为继承自CObject的一个独立功能类。