#include<fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream in;
in.open("test.txt");
if(!in)
{
cerr << "打開檔案失敗"<< endl;
return 0;
}
char x;
while(in >> x)
{
cout << x;
}
cout << endl;
in.close();
return 0;
}
C:\Users\Administrator\CLionProjects\7fileinout\cmake-build-debug\7fileinout.exe
打開檔案失敗
行程已結束,退出代碼 0
uj5u.com熱心網友回復:
在打開那里設定一個斷點,然后在watch視窗里面輸入err,hr,查看一下錯誤值uj5u.com熱心網友回復:
1.用絕對路徑2.把檔案放到可執行檔案同級目錄下
uj5u.com熱心網友回復:
用正確的路徑,你這個test.txt指向哪里都不知道機器自然打不開uj5u.com熱心網友回復:
然后你那個char好像也怪怪的,你試試string,最好用STL的vessel而不是C式的轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/35918.html
標籤:C++ 語言
上一篇:C++馬走日問題
