【发布时间】:2021-02-21 16:52:31
【问题描述】:
我使用 Dev C++ 作为 IDE,Windows 10,这是代码
#include<stdio.h>
main(){
FILE *f;
f=fopen("C:\\Users\\min2\\Documents\\asd.txt", "w"); //(did not work)
//f=fopen("C:/Users/min2/Documents/asd.txt", "w"); (did not work)
//f=fopen("asd.txt", "w"); (did not work)
if(f==NULL)printf("Did not work"); //this is what im getting in the console
else printf("It worked");
fclose(f);
}
它不是在创建 .txt。我正在尝试在文档中执行此操作。我在桌子上试过,但它也不起作用。它不会创建文件。
【问题讨论】:
-
perror("fopen")打印什么? -
或
GetLastError()在 Windows 中。 -
文件夹是否存在?如果有,您是否有权在那里创建文件?
-
既然您使用的是 C++,为什么不试试
fstream?哦,顺便说一句,main缺少返回类型。 -
@anastaciu 这真的取决于当时工作目录的设置位置。