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

查看:81
本文介绍了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 filesmicrosoft visual studio 8vcincludestdio.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>

预处理器指令也可以添加到您的项目设置中,以影响项目下的所有文件.为此,将 _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天全站免登陆