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.
有没有一种方法可以让用户连续输入一堆整数,但是当她/他完成后,她/他会在完成后按 -111(必须是这个数字)而不必初始化另一种数据类型?
像这样:
while(what the user puts in is not -111)
这非常简单。但另一个答案甚至不处理输入结束,所以这更好
int i; while (cin >> i && i != -111) { ... }
这个怎么样
int i; do { std::cin >> i; } while (i != -111);