今天在看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
为什么可以用while(cin)? /** * @brief The quick-and-easy status check. * * This allows you to write constructs such as * "if (!a_stream) ..." and "while (a_stream) ..." */ operator void*() const { return this->fail() ? 0 : const_cast<
cin是istream类的对象,它是从标准输入设备(键盘)获取数据,程序中的变量通过流提取符">>"从流中提取数据.流提取符">>"从流中提取数据时跳过输入流中的空格.tab键.换行符等空白字符.注意:只有在输入完数据再按回车键后,该行数据才被送入键盘缓存区,形成输入流,提取运算符">>"才能从中提取数据.需要注意保证从流中读取数据能正常运行. 例如: int a,b; cin>>a
Before being an ubiquous communications gadget, a mobile was just a structure made of strings and wires suspending colourfull things. This kind of mobile is usually found hanging over cradles of small babies. The figure illustrates a simple mobile.