2

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

user1505497
  • 201
  • 5
  • 11

1 Answers1

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.

masoud
  • 51,434
  • 14
  • 119
  • 190