このコードが完了すると、余分な反復 (余分な行が出力される) が発生するのはなぜですか? EOF に余分な改行が必要ですか? EOF をマークするために余分な文字や特殊文字を追加する必要はありません。
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
ifstream infile("dictionary.txt"); // one word per line
string text;
while(infile){
infile >> text;
cout << text << endl;
}
infile.close();
return 0;
}