I know all about the problems cin>> can cause, but I thought getline solved that. With this program
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string word;
while (getline(cin, word))
{
cout<<"Read -- "<< word <<endl;
}
cout<<"Enter one last word: "<<flush;
getline(cin, word);
cout<<"Read -- "<< word <<endl;
}
Everything in the loop reads just find, but when I hit ctrl+z to get out of the loop, the next call to getline is skipped. I've tried this in Borland 5.5 and Dev-C++ 4 with the same results. Using cin.ignore() doesn't have any effect, nor does reading one character in a loop until there's nothing left. I have to be doing something wrong, but I can't see what. Any ideas?