fopen已弃用警告 [英] fopen deprecated warning

查看:164
本文介绍了fopen已弃用警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Studio 2005 C ++编译器上,当我的代码使用 fopen 和此类调用时,我得到以下警告。

On Visual Studio 2005 C++ compiler, I get the following warning when my code uses the fopen and such calls.

1>foo.cpp(5) : warning C4996: 'fopen' was declared deprecated
1>        c:\program files\microsoft visual studio 8\vc\include\stdio.h(234) : see declaration of 'fopen'
1>        Message: 'This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'

如何防止这种情况发生?

How do I prevent this?

推荐答案

Microsoft似乎已弃用了许多使用缓冲区来提高代码安全性的调用。但是,他们提供的解决方案不是便携式的。无论如何,如果您对使用安全的呼叫版本(例如 fopen_s )不感兴趣,则需要在包含的头文件之前放置 _CRT_SECURE_NO_DEPRECATE 的定义。例如:

It looks like Microsoft has deprecated lots of calls which use buffers to improve code security. However, the solutions they're providing aren't portable. Anyway, if you aren't interested in using the secure version of their calls (like fopen_s), you need to place a definition of _CRT_SECURE_NO_DEPRECATE before your included header files. For example:

#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>

还可以将preprocessor指令添加到项目设置中,以对项目下的所有文件生效。为此,将 _CRT_SECURE_NO_DEPRECATE 添加到项目属性->配置属性-> C / C ++->预处理程序->预处理程序定义

The preprocessor directive can also be added to your project settings to effect it on all the files under the project. To do this add _CRT_SECURE_NO_DEPRECATE to Project Properties -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions.

这篇关于fopen已弃用警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆