How does that funky while (cin >> foo) syntax work?
See the previous FAQ for an example of the “funky while (cin >> foo) syntax.” The expression (cin >> foo) calls the appropriate operator>> (for example, it calls the operator>> that takes an istream on the left and, if foo is of type int, an int& on the right). The istream operator>> functions return their left argument by convention, which in this case means it will return cin. Next the compiler notices that the returned istream is in a boolean context, so it calls the “cast” operator istream::operator bool(). I.e., in this case, it calls cin.operator bool(), just as if you had casted it explicitly such as (bool)cin or bool(cin). (Note: if your compiler doesn’t yet support the bool type, istream::operator void*() will be called instead.) The operator bool() cast operator returns true if the stream is in a good state, or false if it’s in a failed state (in the void* case, the return values will be some non-NULL pointer or the NULL pointer, respectively). For example, if you read one to