This function or variable may be unsafe Consider using xxx instead

问题:

在Visual C++ 6.0 以下执行正常的代码放到Visual Studio 20xx系列里就跑不动了,有时候会提演示样例如以下错误:

error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.


解决方式:

有两种解决方法:

1、依照提示说的做,把fopen换成fopen_s(类似的错误一般都是提示xxx函数不安全。加个后缀_s就能够解决的)。可是加完了你可能会发现...參数类型不匹配了,所以还要改參数类型,非常麻烦有没有!所以有了另外一种方法!

2、以Visual Studio 2012为例,打开工程后,选择Project -> project name Properties... -> Configuration Properties -> C/C++ -> Command Line 在以下的Additional Options 加上这一句:/D "_CRT_SECURE_NO_DEPRECATE" 然后确定就能够了,又一次编译程序就没有警告了!





posted @ 2016-04-16 08:08  zfyouxi  阅读(268)  评论(0编辑  收藏  举报