Why is it possible to read a file using a while loop such as
while (file >> variable)
Or
while (getline(xx, yy))
Do the >> and getline functions return boolean values ?
Answer
The stream operators evaluate to a reference to the stream itself. This allows chaining e.g. file >> variable >> variable >> variable.
When you combine it with the fact that the stream object is convertible to boolean (whose value is true iff no error flags are set) and, yes, you get that effect.
No comments:
Post a Comment