64,651
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
int main()
{
int a = -1;
std::cin >> a; // 运行时分别给1和a
std::cout << "a = " << a << std::endl;
std::cout << "istream flag : " << std::cin.fail() << std::endl;
}
if (cin >> a)
{
// what to do if succeed
}
else
{
// what to do if fail
}