Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Lippman 5] I think that there is a bug on page 313

25 views
Skip to first unread message

Christiano

unread,
Mar 25, 2018, 3:01:52 PM3/25/18
to
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


Christiano

unread,
Mar 25, 2018, 3:04:56 PM3/25/18
to
In my opinion the correct program should be:

auto old_state = cin.rdstate(); // remember the current state of cin
cin.clear(); // make cin valid
process_input(cin); // use cin
cin.clear(old_state); // now reset cin to its old state
0 new messages