开发者

Do input operands return booleans in c++?

Reading through accelerated c++, they give an example I don't understand. It's a while loop with condition (cin>>x). At this point in the script, x has been declared as a double. I understand that the loop executes as long开发者_StackOverflow社区 as x successfully receives input, but is >> returning a boolean? I guess I just need a little help understanding exactly what it is >> and << do.... Also while we're on the subject, whats the difference between iostream, ios and iomanip


actually, they return themselves, that is,

std::cin >> foo

is an expression (with a side effect) that happens to return std::cin. It also happens that iostreams can be converted to bool, they are true if they are ready to recieve input, or have output to provide, and false if they are closed or at the end of their respective files.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜