Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可以说我正在制作一个数学程序简单的算术测验程序。它给出一个随机数并要求用户以整数或 q 形式输入答案以退出。这可能吗?
以字符串形式获取答案,然后检查是否为 == "q",退出,否则,将其转换为整数。
#include <iostream> #include <cstdlib> int main() { std::string got; std::cin >> got; if(got == "q") return 0; else { int i = std::atoi(got.c_str()); std::cout << i; } return 0; }