The std::basic_ios base class provides an operator bool() method that returns a boolean representing the reality of the stream. For example, if reading reached the end of the file without capturing any characters, then std::ios_base::failbit will be set in the stream. Then operator bool() will be called, returning !fail() , after which the extraction will stop because the condition is false.
The conditional expression is an explicit Boolean conversion, so this is:
while (in >> s)
equivalent to this
while (static_cast<bool>(in >> s))
which is equivalent to this
while ((in >> s).operator bool())
which is equivalent
while (!(in >> s).fail())
source share