条件状态2

#include <iostream>

using namespace std;

int main()
{
	int sum = 0, value;
	while (cin >> value, !cin.eof())
	{
		if (cin.bad())
			throw std::runtime_error("IO stream corrupted");  // 抛出异常,
		if (cin.fail())
		{
			cerr << "bad date, try again" << endl;
			cin.clear(); // 恢复流的状态,
			cin.ignore(200, '\n'); // ignore忽略,忽略掉200,
			continue;
		}
		sum += value;
		cout << "sum is: " << sum << endl;
		
	}
	return 0;
}

你可能感兴趣的:(条件状态2)