#ifdef DEBUG_INPUT freopen("input", "r", stdin); // freopen("output", "w", stdout); #endif// DEBUG_INPUT string a, b; int parseNum; while (cin >> a >> b) { bool a_type = isNum(a); bool b_type = isNum(b); int a_int, b_int; int flag = true; // 判断非数字的情况 if (!a_type) { flag = false; std::cerr << "Error: a=" << a << " is not a num." << endl; } if (!b_type) { flag = false; std::cerr << "Error: b=" << b << " is not a num." << endl; } if (!flag) { cout << "Try Again." << endl; continue; }
try { a_int = stoi(a, string::size_type()); } catch (const std::out_of_range &oor) { std::cerr << "Error: Value of a out of range! " << oor.what() << endl; flag = false; } try { b_int = stoi(b, string::size_type()); } catch (const std::out_of_range &oor) { std::cerr << "Error: Value of b out of range! " << oor.what() << endl; flag = false; }
ll ans = getAdd(a_int, b_int);
if (!flag) { cout << "Try Again." << endl; continue; } else { cout << "Correct! The value is " << ans << "." << endl; } }
#ifdef DEBUG_INPUT freopen("input", "r", stdin); // freopen("output", "w", stdout); #endif// DEBUG_INPUT string a, b; int parseNum; while (cin >> a >> b) { bool a_type = isNum(a); bool b_type = isNum(b); int a_int, b_int; int flag = true; // 判断非数字的情况 if (!a_type) { flag = false; std::cerr << "Error: a=" << a << " is not a num." << endl; } if (!b_type) { flag = false; std::cerr << "Error: b=" << b << " is not a num." << endl; } if (!flag) { cout << "Try Again." << endl; continue; }
try { a_int = stoi(a, string::size_type()); } catch (const std::out_of_range &oor) { std::cerr << "Error: Value of a out of range! " << oor.what() << endl; flag = false; } try { b_int = stoi(b, string::size_type()); } catch (const std::out_of_range &oor) { std::cerr << "Error: Value of b out of range! " << oor.what() << endl; flag = false; }
ll ans = getAdd(a_int, b_int);
if (!flag) { cout << "Try Again." << endl; continue; } else { cout << "Correct! The value is " << ans << "." << endl; } }