最近在学条件状态好难啊,这个当输入字母时,是死循环?
程序代码:
#include<iostream> #include <string> #include<stdexcept> #include <bitset> using namespace::std; 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(istream::failbit); continue; } } }