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
  • 459
  • 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,915
  • 8
  • 35
  • 53
Hugal31
  • 1,610
  • 1
  • 14
  • 27