问题
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