Since you are reading int variables, everything you enter must be an integer or the input statement will not work. If you want to read characters and check if they are numbers, you must read char variables, and then before using them you need to convert them to the corresponding integer values.
Try something like:
inline int to_int(const char ch) { return ch - '0'; }
If you just want to enter two common integer values, then you are already on the right track, you just need to make sure that the input is ok:
int a, b; if (std::cin >> a >> b) std::cout << a + b << '\n'; else std::cout << "Error in input (most likely not integers in input)\n";
source share