#include <iostream> // For standard streams
int main()
{
int a = -1;
std::cin >> a;
std::cout << "state-fail:"<<std::cin.fail() << std::endl;
std::cout << "state-good:"<<std::cin.good() << std::endl;
std::cout << "state-bad:"<<std::cin.bad() << std::endl;
std::cout << "state-eof:"<<std::cin.eof() << std::endl;
std::cin.clear();
std::cout << " after std::cin.clear()" << std::endl;
std::cout << "state-fail:"<<std::cin.fail() << std::endl;
std::cout << "state-good:"<<std::cin.good() << std::endl;
std::cout << "state-bad:"<<std::cin.bad() << std::endl;
std::cout << "state-eof:"<<std::cin.eof() << std::endl;
std::cout << "a = " << a << std::endl;
std::cin >> a;//并没有执行!!!!!
std::cout << "a = " << a << std::endl;
return 0;
}
>> ./a.out
q
state-fail:1
state-good:0
state-bad:0
state-eof:0
after std::cin.clear()
state-fail:0
state-good:1
state-bad:0
state-eof:0
a = 0
a = 0
首先输入q,导致std::cin失效,但是我clear()以后,依然不可用,没有道理啊。
--
FROM 123.119.150.*