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)