Visual Studio 2012 编译错误【error C4996: 'scanf': This function or variable may be unsafe. 】的解决方案

来源:互联网 发布:拔罐 菲尔普斯 知乎 编辑:程序博客网 时间:2024/05/21 10:02

This function or variable may be unsafe错误

在VS 2012 中编译 C 语言项目,如果使用了 scanf 、fopen、printf等函数,编译时便会提示如下错误:

error C4996: ‘scanf’: This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

原因是Visual C++ 2012 使用了更加安全的 run-time library routines 。新的Security CRT functions(就是那些带有“_s”后缀的函数),请参见:
《CRT函数的安全增强的版本》

解决方案
在代码文件最开始前面加入代码

#pragma warning(disable:4996)

1 1
原创粉丝点击