C4996 ---- _CRT_SECURE_NO_WARNINGS

来源:互联网 发布:淘宝网优惠券领取 编辑:程序博客网 时间:2024/05/21 13:54

问题:

在使用老版本的CRT(C Run-Time)函数,如strcpy、strcat、fopen时就会出现一些警告信息,在vs2102中我的出现的是如下错误信息:

error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS;

error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS;

原因:

Many old CRT functions have newer, more secure versions. If a secure function exists, the older, less secure version is marked as deprecated and the new version has the _s ("secure") suffix.

In this context, "deprecated" just means that a function's use is not recommended; it does not indicate that the function is scheduled to be removed from the CRT.

解决方案:

方案一:项目-->属性-->配置属性-->C/C++-->预处理器,在"预处理器定义"中加入"_CRT_SECURE_NO_WARNINGS"。

方案二:项目-->属性-->配置属性-->C/C++-->命令行,在"其他选项"中加入"/D  _CRT_SECURE_NO_WARNINGS"。

方案三:在代码中加入预处理指令#pragma warning( disable : 4996 )。

方案四:项目-->属性-->配置属性-->C/C++-->常规,将"SDL检查"设置为"否"。

关于SDL:Adds recommended Security Development Lifecycle (SDL) checks. These checks include extra security-relevant warnings as errors, and additional secure code-generation features.这也就是为什么在上面我的提示为error,当把"SDL检查"设置为"否"后,提示便会变为warning,如下:

warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS;


参考链接:

Compiler Warning (level 3) C4996

Security Features in the CRT

/sdl (Enable Additional Security Checks)

0 0
原创粉丝点击