Error C4996: 'swprintf' 新旧版本问题

来源:互联网 发布:编程基础教学 编辑:程序博客网 时间:2024/05/16 10:22

运行程序出现如下错误:


error C4996: 'swprintf': swprintf has been changed to conform with the ISO C standard, adding an extra character count parameter. To use traditional Microsoft swprintf, set _CRT_NON_CONFORMING_SWPRINTFS.


查阅MSDN:

In Visual C++ 2005, swprintf conforms to the ISO C Standard, which requires the second parameter,count, of type size_t. To force the old nonstandard behavior, define_CRT_NON_CONFORMING_SWPRINTFS. In a future version, the old behavior may be removed, so code should be changed to use the new conformant behavior.


说明在VC++2005之后,需要在swprintf函数的第二个函数加上count这个参数。

第一种方法:

比如原先swprintf(wsSize, L"%d", sizeDownload);改成swprintf(wsSize, 255,L"%d", sizeDownload);

第二种方法:

在项目属性的C/C++ -> 预处理器 -> 预处理器定义中加_CRT_NON_CONFORMING_SWPRINTFS这个属性。


第二种方法相对而言不安全,尽量使用第一种的方法。

0 0
原创粉丝点击