错误C4996:Visual Studio:在C中使用fopen时为什么会出现错误? [英] error C4996: visual studio: why do I get an error when I use fopen in c?
本文介绍了错误C4996:Visual Studio:在C中使用fopen时为什么会出现错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚开始使用文件,所以我制作了一个仅打开文件的程序,但出现错误:
I just started to work with files so I made this program that just opens a file but i get the error:
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.
下面是代码:
#include <stdio.h>
int main()
{
FILE* f = fopen("myFile.txt", "w");
if (f == NULL)
{
printf("error\n");
return;
}
fclose(f);
}
推荐答案
您需要在包含之前放置 #define _CRT_SECURE_NO_DEPRECATE
的定义.喜欢,
You need to place a definition of #define _CRT_SECURE_NO_DEPRECATE
before your include. Like,
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
这篇关于错误C4996:Visual Studio:在C中使用fopen时为什么会出现错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文