【问题标题】:fopen function is not creating the file .txtfopen 函数未创建文件 .txt
【发布时间】: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 这真的取决于当时工作目录的设置位置。

标签: c++ fopen


【解决方案1】:

我只是路过说我放弃了这个,我从来没有找到解决方案

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-05
    • 2013-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-26
    • 2014-06-27
    相关资源
    最近更新 更多