I know I can use cin >>
as a condition. But I can't understand its functioning because it is unlike typical condition expressions like a a < b
.
Why it can works as a condition ?
0
votes
1 Answers
2
votes
cin >> a
return cin
. When you put in in the if
, the operator bool
of istream
is called, which return cin.good()
. Look at The documentation of ios::operator bool.
This is the same as if((bool)(cin >> a))
or if((cin >> a).good())
.
std::iostream::operator>>
returns a value. Values can be used in conditions. – jamesdlin