if(cin)到底是什么意思

aaronyih 2014-10-24 11:22:00
if(cin)到底是什么意思
...全文
1592 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
sevendays 2014-10-28
  • 打赏
  • 举报
回复
一旦发现标准输入,即为真,然后执行if内的语句。
  • 打赏
  • 举报
回复
1楼赵老师正解,不过贴的是英文 实际上是调了cin的
explicit operator bool() const
成员函数
赵4老师 2014-10-27
  • 打赏
  • 举报
回复
引用 9 楼 rogone 的回复:
1楼赵老师正解,不过贴的是英文 实际上是调了cin的
explicit operator bool() const
成员函数
货卖识家!
贰到不行 2014-10-26
  • 打赏
  • 举报
回复
cin 是标准输入流类istream的对象 利用cin可以读取来自控制台的数据。当数据匹配或者能够转换到指定类型时则cin的状态为good.则if(cin)为真 当读入的数据不能转换到指定类型,或者数据到达结尾时,或者流出现异常时都会导致cin的状态为bad或者fail则if(cin)为假
Tamce 2014-10-26
  • 打赏
  • 举报
回复
引用 6 楼 mujiok2003 的回复:
检查标准输入流的状态, 如果没有error或者fail或者bad, 则为true
没错,检查cin的状态,通过istream类的类型转换函数实现 如果没有fail,bad,eof,也就是good则为true,类似于if(cin.good())
赵4老师 2014-10-24
  • 打赏
  • 举报
回复 1
计算机组成原理→DOS命令→汇编语言→C语言(不包括C++)、代码书写规范→数据结构、编译原理、操作系统→计算机网络、数据库原理、正则表达式→其它语言(包括C++)、架构…… 对学习编程者的忠告: 多用小脑和手,少用大脑、眼睛和嘴,会更快地学会编程! 眼过千遍不如手过一遍! 书看千行不如手敲一行! 手敲千行不如单步一行! 单步源代码千行不如单步Debug版对应汇编一行! 单步Debug版对应汇编千行不如单步Release版对应汇编一行! 单步类的实例“构造”或“复制”或“作为函数参数”或“作为函数返回值返回”或“参加各种运算”或“退出作用域”的语句对应的汇编代码几步后,就会来到该类的“构造函数”或“复制构造函数”或“运算符重载”或“析构函数”对应的C/C++源代码处。 VC调试时按Alt+8、Alt+7、Alt+6和Alt+5,打开汇编窗口、堆栈窗口、内存窗口和寄存器窗口看每句C对应的汇编、单步执行并观察相应堆栈、内存和寄存器变化,这样过一遍不就啥都明白了吗。 对VC来说,所谓‘调试时’就是编译连接通过以后,按F10或F11键单步执行一步以后的时候,或者在某行按F9设了断点后按F5执行停在该断点处的时候。 (Turbo C或Borland C用Turbo Debugger调试,Linux或Unix下用GDB调试时,看每句C对应的汇编并单步执行观察相应内存和寄存器变化。)
赵4老师 2014-10-24
  • 打赏
  • 举报
回复
Reference <ios> ios operator bool public member function <ios> <iostream> std::ios::operator booloperator void*() const; explicit operator bool() const;Evaluate stream Returns whether an error flag is set (either failbit or badbit). Notice that this function does not return the same as member good, but the opposite of member fail. The function returns a null pointer if at least one of these error flags is set, and some other value otherwise. The function returns false if at least one of these error flags is set, and true otherwise. Parameters none Return Value A null pointer if at least one of failbit or badbit is set. Some other value otherwise. true if none of failbit or badbit is set. false otherwise. Example 123456789101112131415 // evaluating a stream #include <iostream> // std::cerr #include <fstream> // std::ifstream int main () { std::ifstream is; is.open ("test.txt"); if (is) { // read file } else { std::cerr << "Error opening 'test.txt'\n"; } return 0; } Data races Accesses the stream object. Concurrent access to the same stream object may cause data races. Exception safety Strong guarantee: if an exception is thrown, there are no changes in the stream. See also ios::failCheck whether either failbit or badbit is set (public member function )ios::operator!Evaluate stream (not) (public member function )
mujiok2003 2014-10-24
  • 打赏
  • 举报
回复
检查标准输入流的状态, 如果没有error或者fail或者bad, 则为true
mujiok2003 2014-10-24
  • 打赏
  • 举报
回复
引用 3 楼 jbdjbdjbddd 的回复:
就是判断发现有输入语句或者变量就为真,执行if里边的内容。
引用 4 楼 bojie5744 的回复:
一旦有输入则判断 为真
两位就别扯淡了
  • 打赏
  • 举报
回复
一旦有输入则判断 为真
jbdjbdjbddd 2014-10-24
  • 打赏
  • 举报
回复
就是判断发现有输入语句或者变量就为真,执行if里边的内容。

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧