VS2015 现在错误 C4477 "fprintf"
Posted
技术标签:
【中文标题】VS2015 现在错误 C4477 "fprintf"【英文标题】:VS2015 now error C4477 "fprintf" 【发布时间】:2015-09-09 13:37:51 【问题描述】:到目前为止,VS 完美地编译了我的代码,但现在 VS2015 向我显示了一个我无法理解的警告。
我的代码:
CString nombre=_T("Stack"), dsc=_T("overflow");
_ftprintf(file, _T("%s %s);\n"), nombre, m_dsc);
和 VS2015:
警告 C4477“fwprintf”:格式字符串“%s”需要一个参数 类型 'wchar_t *',但可变参数 1 的类型为 'CString'
为什么?,为什么我不能使用 CString 代替 wchart_t?。我想使用 CString
在此先感谢
何塞米
【问题讨论】:
见msdn.microsoft.com/en-us/library/ms174288.aspx - 5 秒内用谷歌搜索。 尽量避免在 C++ 中使用 C 可变参数函数(如整个printf
和 scanf
系列)。几乎没有编译器能够获得对象权限。
【参考方案1】:
_ftprintf(file, _T("%s %s);\n"), (LPCTSTR)nombre, (LPCTSTR)dsc);
【讨论】:
是的。现在是的。解决方案很简单。 :-)。非常感谢您的快速答复【参考方案2】:我更喜欢 GetString() 而不是 C 风格的转换:
_ftprintf(file, _T("%s %s);\n"), nombre.GetString(), dsc.GetString());
我建议考虑使用 std::fstream 处理文本文件。
【讨论】:
【参考方案3】:#include <tchar.h>
// printf("%s %d %p", str, i, ptr);
_tprintf_s(_T("%s %d %p"), str, i, ptr);
【讨论】:
以上是关于VS2015 现在错误 C4477 "fprintf"的主要内容,如果未能解决你的问题,请参考以下文章