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:
will set both intA and intB becauseCode:int intA, intB; ifstream inFile ( "bar.txt", ifstream::in ); inFile >> intA >> intB;returns a reference inFile.Code:inFile >> intA
However, this also returns some manner of false value, as the following code illustrates:
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?Code:int intA; ifstream inFile ( "bar.txt", ifstream::in ); while (inFile >> intA) { cout << intA << endl; }
Any help would be appreciated. Thanks.



LinkBack URL
About LinkBacks


