由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - could anybody please tell me what " while(cin) {...}" means?
相关主题
how to convert str to doublehow to deal with high dimension for loop?
有没有什么简单的方法从一个double precision的floating point 中读出一个特定的bit?弱问:C的for/while循环能在括号里面continue吗?
register variable互联网这一波泡沫怕是快要退去了
C++怎么不打印小数结尾的0量子计算机搞出来后, 是不是
c++ 不自动initialize变量么?code profiling 的问题
大牛们如何看待Rust?老掉牙的FORTRAN 编程,在REAL*16中,那个是DBLE的替代函数?
[合集] iterator & const_iteratorhow to solve too large positive summation go to negative in fortran programming?
python.org当了?how to get time in milliseconds since 1970 (linux)
相关话题的讨论汇总
话题: cin话题: while话题: anybody话题: means话题: tell
进入Programming版参与讨论
1 (共1页)
w*****j
发帖数: 49
1
RT
X****r
发帖数: 3557
2
An istream (more precisely, an ios) can be automatic converted
to a void *. The result is a non-null pointer of the state of the stream
is good, or null otherwise. It is then implicitly converted to a bool as
the condition of the while statement, i.e. true if stream good.

【在 w*****j 的大作中提到】
: RT
h*****0
发帖数: 4889
3
我觉得这种写法不好。应该加个函数isGood()之类的(自动转换也是调用函数了的,效
率一样),好读多了。

【在 X****r 的大作中提到】
: An istream (more precisely, an ios) can be automatic converted
: to a void *. The result is a non-null pointer of the state of the stream
: is good, or null otherwise. It is then implicitly converted to a bool as
: the condition of the while statement, i.e. true if stream good.

t****t
发帖数: 6806
4
Usually it is used in context such as
while (cin>>something) {
...
};
as opposed to
while (cin) { // while (cin.isgood())
...
}
In fact, std::basic_ios has a lot of members to check state, such as
good(), eof(), fail(), bad(). You can call them explicitly if you want
to do that (actually bool(cin) == !cin.fail()). But usually this is not
correct:
while (cin) { // or while (!cin.fail())
cin>> something;
...
}
check C++ FAQ lite.

【在 h*****0 的大作中提到】
: 我觉得这种写法不好。应该加个函数isGood()之类的(自动转换也是调用函数了的,效
: 率一样),好读多了。

1 (共1页)
进入Programming版参与讨论
相关主题
how to get time in milliseconds since 1970 (linux)c++ 不自动initialize变量么?
how to get time() result in millisecond precision? (转载)大牛们如何看待Rust?
CPU double precision (转载)[合集] iterator & const_iterator
fortran 中数值精度怎么保证的?python.org当了?
how to convert str to doublehow to deal with high dimension for loop?
有没有什么简单的方法从一个double precision的floating point 中读出一个特定的bit?弱问:C的for/while循环能在括号里面continue吗?
register variable互联网这一波泡沫怕是快要退去了
C++怎么不打印小数结尾的0量子计算机搞出来后, 是不是
相关话题的讨论汇总
话题: cin话题: while话题: anybody话题: means话题: tell