Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
主に:
ifstream file("text.txt"); string line; while (file) { file>>line; cout<<line<<endl; }
text.txt:
hello goodbye
出力:
hello goodbye goodbye
最後の行が2回印刷されるのはなぜですか?
複製:「さようなら」を初めて読んだとき、ファイルの終わりに到達して次の反復に進んだことを知りません。次に、読み取りに失敗し、eofビットセットを取得しますが、現在の値を出力しますline。これは「さようなら」のままです。
eof
line