1

I have this code:

int temp;
cin >> temp;
if(!cin){
    cout << "a";
}else{
    cout << "b";
}        

When I put a number, it printed b, but when I put a character, it printed a. What is happening here?

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
  • Consult a C++ reference to look at how the various `operators` are overloaded within `cin`. If you don't know what operator overloading is yet, then start by searching for a definition of that. – underscore_d Sep 23 '15 at 17:28
  • See [Purpose of if(cin)](http://stackoverflow.com/a/20962046/597607) – Bo Persson Sep 23 '15 at 17:36

0 Answers0