我之前做了一個小程式,關于檔案輸入輸出的,但是出現了一些小問題,下面就是我的代碼。
int save()
{
FILE* fp;
int i;
if ((fp = fopen("D:\\stu_list.txt", "wb")) == NULL)
{
printf("cannot open file\n") ;
return 0;
}
for (i = 0; i < SIZE; i++)
if (fwrite(&stud[i], sizeof(struct student), 1, fp) != 1)
printf("file write error\n");
else printf("file writing done\n");
fclose(fp);
return 0;
}
調試的時候總是說fopen用法有誤:
1>e:/project/htt/ishow/functions.cpp(56) : warning 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.
經過網上查找,發現解決方法為:
右擊工程 - 屬性 - 配置屬性 - C/C++ - 指令行;
指令行增加 /D _CRT_SECURE_NO_WARNINGS
這樣問題就完美的解決了。