簡體   English   中英

CLion IDE 中的文件 I/O

[英]File I/O in CLion IDE

我正在使用 CLion IDE 在 C 中進行編碼,並且我在某事中被阻止了。

#include<stdio.h>

int main()
{
    FILE* f;
    f = fopen("address.txt", "r+");
    if(f == NULL){
        printf("File Open Error!");
        return 0;
    }

    char str[100][100];
    for(int i = 0 ; i < 100 ; i ++){
        fscanf(f, "%s", str[i]);
    }
    fclose(f);
    f = fopen("out.txt", "w+");
    for(int i = 0 ; i < 100 ; i ++){
        fprintf(f, "%s\n", str[i]);
    }
    return 0;
}

CLion 告訴我“文件打開錯誤”。 所以,我嘗試了 DEV C++,並且成功了。 我不知道這個問題

r+模式意味着文件應該存在,請參閱http://www.cplusplus.com/reference/cstdio/fopen/

因為你沒有使用絕對文件路徑,那么程序搜索當前目錄下的文件, Dev C++CLion顯然會在不同目錄下生成exe文件,其中一個address.txt存在,另一個沒有。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM