I found a piece of C-ish C++ code and asked myself the (slightly academic) question, what implicit type conversions happen here to arrive at the bool
that if
requires?
int val;
if( (std::cin >> val) == 0 )
...
I got this far:
std::cin >> val
returns (a ref to)cin
, thusistream&
- Therefore
==
receivescin
and0
as operands, i.e.istream
andint
I don't think there is a bool operator==(istream&, int)
available (nor the respective member function in istream
), so is there a conversion involved?
Just to be clear, the programmers intention was to check if the input was a success, i.e. should have written if(!(std::cin >> val))
.