代码如下,请问这段:
cin.clear();
while (cin.get() != '\n')
continue;
是啥意思,为什么输入错误程序就中止了呢?while循环里的语句是啥意思呢?cin.clear 是啥意思?
int fill_array(double ar[], int limit) {
double temp;
int i;
for (i = 0; i < limit; i++) {
cout << "Enter value#" << (i + 1) << ":";
cin >> temp;
if (!cin) {
cin.clear();
while (cin.get() != '\n')
continue;
cout << "Bad input;input process terminated.\n";
break;
}
else if (temp < 0)
break;
ar[i] = temp;
}
return i;
}