Page 313 has the following program:
auto old_state = cin.rdstate(); // remember the current state of cin
cin.clear(); // make cin valid
process_input(cin); // use cin
cin.setstate(old_state); // now reset cin to its old state
But in my opinion this program is wrong. Imagine this situation:
first line stores {fail=1, eof=1, bad=0} in the old_state variable
second line clears cin flags
third line result cin's flag to be {fail=1, eof=0, bad=1}
Fourth line sets flags to {fail=1, eof=1, bad=1}
However {fail=1, eof=1, bad=1} != {fail=1, eof=1, bad=0}
So, this program is wrong (I think).
Can you confirm, please? Thank you.
------------------------------------------
I can paste part of the book according to the law of fair use:
https://www.copyright.gov/fair-use/more-info.html
Lippman 5:
https://www.pearson.com/us/higher-education/program/Lippman-C-Primer-5th-Edition/PGM270560.html