|
正在学c++,看c++primer
第八章中的一个事例程序:
int main(){
int ival;
while(cin>>ival, !cin.eof()){
if(cin.bad())throw runtime_error("IO stream corrupted");
if(cin.fail()) {
cerr<<"Bad data, try again";
cin.clear();
continue;
cout<<ival<<endl;
}
}
}
./a.out
a
Bad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try againBad data, try
输入非数字字符,程序怎么进入死循环了,奇怪。
哪位能指点一下吗?先谢谢了! |
|