所以我想通過文字來複制一個字從文件1到file2,但我的代碼在打開文件2(輸出文件)C++的ofstream無法讀取一個.txt
void myFile::printWords(string inFile, string outFile)
{
ifstream file;
ofstream file2;
file.open(inFile);
file2.open(outFile);
if (!file.is_open() && !file2.is_open()){
string word;
while (!file.eof()){
file >> word;
file2 << word << '\n';
}
}
else{
cout << "error" << endl;
}
file.close();
file2.close();
}
任何想法,爲什麼失敗?
我認爲你的代碼是一個問題:檢查兩個文件被打開沒有正確實施 – lowtech
哦天哪,我複製了另一個函數的檢查,並忘記刪除(!)...謝謝 – XEvans