【发布时间】:2014-03-16 01:56:39
【问题描述】:
int n;
while(cin>>n)
cout << n; // Run by the program if received an int value
cout << "Break from loop"; // Run by the program
cin >> n; // Skipped by the program
cout << n; // Run by the program
在使用字符终止 while 循环后无法接受另一个输入。
如果循环内的输入已使用非整数/浮点值终止,如何接受另一个输入。
【问题讨论】:
-
这是一个正确的观察。
-
你的问题到底是什么?
-
有谁知道比
cin.clear(); getline(cin,dummystring);更干净的方法吗? -
@Beta 严重问题?
-
@0x499602D2:是的,对无法搜索“reset cin”的用户有点嘲讽。
标签: c++ loops while-loop infinite-loop