Cin object return value c++ [duplicate]

谁说胖子不能爱 提交于 2020-01-24 19:05:27

问题


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())?


回答1:


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.



来源:https://stackoverflow.com/questions/19385141/cin-object-return-value-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!