0
votes

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 ?

1
std::iostream::operator>> returns a value. Values can be used in conditions.jamesdlin
To be more precise: Values that are convertible to boolean can be used in conditions.eerorika

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