[英]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.