Why do I get an extra iteration (extra line printed) when this code completes? Does there need to be an extra newline at the EOF? I would prefer not having to add extra/special characters to mark the 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;
}