c++ reading from cin
If I have:
double x;
cin >> x;
then I proceed to enter a character or开发者_如何学JAVA a string, what would happen? And what would the statement cin >> x
return?
The istream::operator>>
always returns an istream
object, no matter what. The value of x
however would be undefined, and the istream
would be "errored" and wouldn't work again till you cleared the error state.
This is just from memory and I really haven't thought about this before, so if someone sees that this is wrong, I'll remove it.
精彩评论