开发者

c++ reading from cin

开发者 https://www.devze.com 2023-03-04 05:28 出处:网络
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&g

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消