This is C’s classic filter framework for C++ objects. The loop is terminated if the failbit
or badbit is set. This happens when an error occurred or at end-of-file (the attempt to read at
end-of-file results in setting eofbit and failbit; see Section 15.4.1, page 758). By default, operator
>> skips leading whitespaces. This is normally exactly what is desired. However, if obj is
of type char, whitespace is normally considered to be significant. In this case, you can use the
put() and get() member functions of streams (see Section 15.5.3, page 772) or, even better, an
istreambuf_iterator (see Section 15.13.2, page 831) to implement an I/O filter.
With operator !, the inverse test can be performed. The operator is defined to return whether a
stream has run into an error; that is, the operator returns true if failbit or badbit is set. The
operator can be used like this