Hi this is a question regarding how flushing an ifstream works.
I have a text file :
a
1
and execute the following code:
1 2 3 4 5 6 7 8 9 10
int i;
char a;
ifstream in ("test.txt");
in >> i;
if(in.fail())in.clear();
in >> i;
if(in.fail()) cout << "Your integer is still invalid!" << endl;
cout << i << endl;
And regardless of clearing my instream, I still reach a fail state from reading in "1". My question is how reading works with file streams. What should I be doing properly to make the second if condition be false?