First at all, the expression
looks into the stream checks if there is a number to get from at front of the input queue and if so, stores into myNumber. But now comes the issue.
myStream >> myNumber
can be rewritten into
myStream.operator>>(myNumber);
, and so it returns the stream ojects itself, since this is the declaration of operator>>.
The if clause want to have boolean to check if its true and false! UhOh! What we have is a std::istream object. (myStream was return from operator>>).
The trick is, that the class std::istream defines a bool operation, means, if you expect myStream to be a bool, it will be converted with the member function good(). In other words. If you do a check on a stream (convert it to bool) it will be false if an error occurs, or true if everything was fine.
Soooooooo
|
if (myStream >> myNumber) // will be true, if worked, false if error occured.
|
what we still have to know is: When does an error occur? It does occur if you expect an integer, (like in your case) but the first chars in your string are no numbers, but some alphabetic chars. In other words, if the Stream cant extract what you wish for, because we cant match in our input any numbers, than myStream will set some error flags and your expression will be evaluated as false!
Ahm... i tipped really a lot. Did you understand or more?
Sorry, my english is not good.
Maikel