I don't think there is a
bool operator==(istream&, int)
available [...] so is there a conversion involved?
Indeed. There is a conversion operator to bool
that returns true
if no errors occurred, and false
otherwise.
Per paragraph 27.5.5.4/1 of the C++11 Standard:
explicit operator bool() const;
1 Returns:
!fail()
.
So the expression (cin >> val
) gives you back a (reference to) cin
, which is the left operand of ==
. The right operand is 0
.
Now cin
can be converted to bool
, and that allows the comparison with 0
. In other words, your if
statement is equivalent to:
if (!(std::cin >> val))
{
// ...
}