Erorr 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* fp; //定义文件指针变量fp
fp = fopen("test.dat", "r");
if (fp == NULL)
puts("文件打开失败");
else
printf("文件打开成功");
if (fp == NULL)
return 0;
fclose(fp);
return 0;
}
按照错误信息给出的有两种解决方式。
方式一:使用fopen_s()函数代替fopen()函数。
fopen_s()函数的原型这里就不再写出,直接给出fopen_s()所需的3个参数。