Cin对象返回值c ++ [英] Cin object return value c++

查看:121
本文介绍了Cin对象返回值c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问问什么是cin的回报价值?我知道这是istream对象,当它用于表达式像 if(!cin)实际上调用了一些函数,我想知道什么函数其实是。
if(!cin)和if(cin.fail())一样吗?

解决方案

是的。



cin 重载转换操作符,并且它们返回标志状态 fail()



/ p>

  operator void *()const {
return!fail
}

显式运算符bool(){
return!fail();
}

bool operator!()const {
return fail();
}

查看此处此处。 / p>

I woud like to ask what is return value of cin? I know it is istream object and when it is used in expression like if(!cin) there is actually called some function and I woud like to know what function it actually is. cin.fail() or cin.good() or.. Is if(!cin) same as if(cin.fail())?

解决方案

Yes.

cin overloads casting operators, and they return flag status fail().

A possible implementation:

operator void*() const {
    return !fail();
}

explicit operator bool(){
   return !fail();
}

bool operator!() const {
   return fail();
}

Look at here and here.

这篇关于Cin对象返回值c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆