扫码关注官方订阅号
'>>'是cin的一个运算符重载函数,而且cin要满足连续使用>> >>的要求,所以返回值应该是istream对象,但是istream对象的话不就不能判断返回值是true 还是false了吗?
为什么while可以判断?(还是说返回值不是istream?这是我猜想的)
学习是最好的投资!
推荐看看这篇文章http://www.perfect-is-shit.com/deep-into-while-cin.html
cin是istream 重载了下面两个:
cin
istream
istream& operator>>(istream &, string &);
operator bool();
调用那句话的时候 两个依次执行
转换为布尔值的逻辑是 如果fail bad eof至少一个是true 那么转换结果为false 反之为true
fail
bad
eof
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
推荐看看这篇文章
http://www.perfect-is-shit.com/deep-into-while-cin.html
cin
是istream
重载了下面两个:istream& operator>>(istream &, string &);
operator bool();
调用那句话的时候 两个依次执行
转换为布尔值的逻辑是 如果
fail
bad
eof
至少一个是true 那么转换结果为false 反之为true