今天在看c++primer的时候,读到其中这样一段话:
When we use an istream as a condition, the effect is to test the state of the stream. If the stream is validthat is, if it is still possible to read another input then the test succeeds. An istream becomes invalid when we hit end-of-file or encounter an invalid input, such as reading a value that is not an integer. An istream that is in an invalid state will cause the condition to fail.
其对应代码是:while (std::cin >> value)
...
开始就觉得这样有点不对劲,但是也不知道是哪里不对劲.仔细一想,原来是觉得这个cin的位置十分诡异...
原来我们最常用的就是直接输入或者直接输出.比如cin>>value;或者cout<<value;现在把这个放到while里面进行判断.
难道cin与cout的返回值是bool型的?好像也说不过去.
GOOGLE之~~
分下面几点来说明:
1.c