istream &func(istream &in)
{
string data;
while (in >> data, !in.eof()) {
if (in.bad())
throw runtime_error("IO stream corrupted");
if (in.fail()) {
cerr << "bad data, try again" << endl;
in.clear();
in.ignore(200);
continue;
}
cout << data << endl;;
}
//in.clear(istream::eofbit | istream::failbit);
in.clear();
return in;
}
why in.clear(istream::eofbit | istream::failbit); can not reset the cin?
but in.clear can make it.
PS: I use this function in main(), and use cin as its parameter.
clear is defined like this:
So, effectively,
in.clear();is doing this:in.clear(istream::goodbit);which resets the stream. Callingin.clear(istream::eofbit | istream::failbit);would set both theeofbitandfailbit, I doubt that is what you want.