在之前的vs版本中的文件操作fopen函数操作如下
运行下列代码就可以在制定文件夹创建一个指定格式的文件并输入两行代码
#include <iostream>
int main() {
FILE* fp = NULL;
fp=fopen("D:\\study-C++\\test.txt", "w+");
fprintf(fp,"this is test\n");
fputs("test",fp);
fclose(fp);
return 0;
}
但是到了vs2019版本中就会显示如下:
错误 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.
所以我们将fopen函数修改为fopen_s函数进行操作
fp=fopen("文件路径","模式")
fopen_s(&fp,"文件路劲","模式")
所以我们将代码修改如下
#include <iostream>
int main() {
FILE* fp = NULL;
fopen_s(&fp,"D:\\study-C++\\test.txt", "w+");
fprintf(fp,"this is test\n");
fputs("test",fp);
fclose(fp);
return 0;
}
ctrl+F5运行之后就会在制定文件夹获得一个指定文件,同时会输入两行文字
image.png
image.png
正在进一步加深自己的编程技能,第一次写简书,请各位大佬多多指教,希望能够帮到大家,防止大家踩坑。