我有以下代碼:ifstream f("x.txt");string line;while (f.good()) {
getline(f, line);
// Use line here.}但最后一行讀了兩遍。為什么會發生這種情況,我該如何解決?類似的情況發生在:ifstream f("x.txt");string line;while (!f.eof()) {
getline(f, line);
// Use line here.}
3 回答

慕萊塢森
TA貢獻1810條經驗 獲得超4個贊
ifstream f("x.txt");while (getline(f, line)) { // whatever}

寶慕林4294392
TA貢獻2021條經驗 獲得超8個贊
good()
fail()
- 3 回答
- 0 關注
- 690 瀏覽
添加回答
舉報
0/150
提交
取消