I'm working on a school project that requires the verification of a string for the input, and NOTHING ELSE. However, whenever I pass an int for bug testing (I.E. 0), the program doesn't trigger cin.fail(). For example:
#include <iostream>
#include <string>
using namespace std;
int main() {
string lastName;
cin >> lastName;
if (cin.fail()) {
cout << "INT";
}
else {
cout << "STRING";
}
return 0;
}
INPUT: 1999
OUTPUT: STRING
Why is this the case? I created a personal project using this exact same same structure and had no problems there but can't get it to work properly here.