I'm trying to read input that has ints and strings, in this case an expression like 1 2 +. I've been trying to use cin.fail() to determine if the input is numeric.
int x;
string s;
if (cin >> x){
// do something
} else {
cin >> s;
//do something else
}
I realized this skips input but can't figure out how to solve the problem. Would I have to read everything as a string then check and convert to int? I would like to find a better solution if possible and would be very grateful for any assistance.