在MSVC 2008上使用/analyze
编译时,以下代码生成警告C6284:当在调用函数时需要字符串时,对象作为参数'%s'传递。
CString strTmp, str;
str = L"aaa.txt"
strTmp.Format (L"File: %s", str);
我正在为此寻找一个很好的解决方案,不需要
static_cast
最佳答案
Microsoft用可变参数函数here描述了CString的用法:
CString kindOfFruit = "bananas";
int howmany = 25;
printf_s( "You have %d %s\n", howmany, (LPCTSTR)kindOfFruit );
另外,您也可以使用
PCXSTR CString::GetString() const;
方法尝试修复警告:CString strTmp, str;
str = L"aaa.txt"
strTmp.Format (L"File: %s", str.GetString());
关于visual-c++ - 使用CString::Format时如何防止C6284?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2598111/