My code is mostly working except for one minor issue. While it should only accept ints, it also accepts user input that start with an int, such as 6abc for example. I saw a fix for this here, but it changed the input type to string and added a lot more lines of code. I'm wondering if there's an easier way to fix this:
int ID;
cout << "Student ID: ";
// error check for integer IDs
while( !( cin >> ID )) {
cout << "Must input an integer ID." << endl ;
cin.clear() ;
cin.ignore( 123, '\n' ) ;
}
std::getlineandstd::stoifunctions can be used for that.cin >> ...for that, but you will have to read into an intermediatestringfirst and then convert that into anintforID, and perform error handling of that conversion instead of (or in addition to)>>.countforcin.ignore(), usestd::numeric_limits<std::streamsize>::max()instead.