hi. i'm trying to write a class with an overloaded >> operator, but i've run into a problem.
when you use this operator with a stream and one of the base datatypes such as int, you can chain them. for example:
Code:
int intA, intB;
ifstream inFile ( "bar.txt", ifstream::in );
inFile >> intA >> intB;
will set both intA and intB because returns a reference inFile.
However, this also returns some manner of false value, as the following code illustrates:
Code:
int intA;
ifstream inFile ( "bar.txt", ifstream::in );
while (inFile >> intA) { cout << intA << endl; }
this will continue reading until it can no longer retrieve anything from the stream, then the loop will break. My question is, how are these both accomplished in the same function? How can one return false as a stream reference?
Any help would be appreciated. Thanks.