Hi. I'm not especially familiar with c++, but I am required to use it for a class. I wrote this little function:
int readLines(istream &in,
in.exceptions(istream::failbit | istream::badbit);
in >> uname;
It is supposed to read in lines, and pass the lines to a handler function. I want it to keep reading lines as long as the input stream is in a good state, return 0 if it reaches eof, and throw an exception for any other input stream error.
However, when I tested this, it also throws an exception when eof is reached, which is not what I intended. How do I get it to not throw an exception on eof, but to throw an exception for everything else?
terminate called after throwing an instance of 'std::ios_base::failure'