先贴代码:
#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检查 中设置为否。