0

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 ?

tsrrhhh
  • 409
  • 1
  • 5
  • 10

1 Answers1

2

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

Jonas
  • 6,812
  • 8
  • 31
  • 51
Hugal31
  • 1,400
  • 1
  • 11
  • 25