I am not sure if I understand cin.fail() correctly. I am trying to get it to return true when a user does not put in an integer.
#include <iostream>
using namespace std;
int main() {
int number;
cout << "Please enter a positive integer: ";
cin >> number;
cout << cin.fail();
return 0;
}
Whenever I enter a non-integer (like 55.687) it returns 0(false) for the cin.fail(). I am not sure why. Any help would be greatly appreciated.