1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| #include <iostream> #include <string>
using std::string; using std::cin; using std::cout; using std::endl;
int main() { int ival; while (cin >> ival, !cin.eof()) { if (cin.bad()) throw std::runtime_error("IO stream corrupted"); if (cin.fail()) { std::cerr << "bad data , try again"; cin.clear(std::istream::failbit); std::istream::iostate old_state = cin.rdstate(); cin.clear(old_state); continue; } cout << "ok," << ival << endl; cout << "hi" << std::flush; cout << "hi" << std::ends; cout << "hi" << std::endl; } return 0; }
|