VS2017中使用fopen函数报错:This function or variable may be unsafe。win10下fopen使用需注意的问题总结

先贴代码:

#include <stdio.h>
#include <string.h>

int main() {

	char *info = "this is test";

	FILE *stream2;

	if ((stream2 = fopen("D:\\log.txt", "a+")) == NULL) // C4996
		printf("The file 'data2' was not opened\n");
	else
	   printf( "The file 'data2' was opened\n" );
	fwrite(info, sizeof(char), strlen(info), stream2);
	fclose(stream2);

	system("pause");

	return 0;
}

上面代码在VS2017中运行会报以下错误:
错误    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.   

因为VS2017默认使用更加安全的fopen_s函数,若要继续使用fopen,需要在 项目->属性->C/C++->SDL检查 中设置为否。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值