#include <iostream>
using namespace std;
int main()
{
int i;
cout << "Enter: " << endl;
cin >> i;
cout << cin.fail() << endl;
}
This is my typical implementation for error checking to make sure I am entering a valid input and this was what I was taught. The problem with my above code is if I type in '4d' it stores the 4 in variable 'i', but leaves the 'd' in the buffer, so the cin.fail() test returns false, but I want it to return true. If I type in 'c' or 'ccc' etc... cin.fail() returns true as I want.
Is there any proper command to test for what I have described?