I'm trying to make a program which reads in a digit and then a character, if there is no digit then it puts a 1 into cin so the 1 will be read as the digit. When I input "1a" I get the correct output but when I input "a" I get "a" as the digit and the character. What am I doing wrong?
Code:#include <iostream> using namespace std; int main() { cout << "start\n"; char c; cin.get(c); if (!isdigit(c)) { cin.putback(c); cin.putback('1'); } else { cin.putback(c); } cin.get(c); cout << "digit " << c << '\n'; cin.get(c); cout << "letter " << c << '\n'; }