mardi 28 mars 2017

What is the difference between eof(), fail(), bad(), and good() in C++ streams?

I am currently learning C++ from the C++ Primer 5th edition. I am confused about the behavior of the methods to check the status of a stream due to seemingly conflicting information. On page 312 it states "If any of badbit, failbit, or eofbit are set, then a condition that evaluates that stream will fail." On the very next page, it says that s.fail() is "true if failbit or badbit in the stream is set" and that "the code that is executed when we use a stream as a condition is equivalent to calling !fail()." This doesn't make sense because any expression that uses fail() should only know about failbit and badbit (since those are what make up fail()'s value) and yet !fail() is equivalent to all three of badbit, failbit, and eofbit being false.

How do these seemingly contradictory statements fit together?

Aucun commentaire:

Enregistrer un commentaire