【发布时间】:2016-04-21 11:08:34
【问题描述】:
cout << "\nPlease enter x-ordinate: ";
cin >> test;
stringstream ss(test);
ss >> x;
while(ss.fail())
{
ss.str("");
cin.clear();
cin.ignore(256, '\n');
cout << "Please enter integer: \n";
cin >> test;
stringstream ss(test);
ss >> x;
cout << x << ss;
}
嗨,我正在尝试测试用户的输入是否为整数,通过使用 sstream 来检查它是否可以转换为整数 x,但是一旦我输入了一个有效的整数,while 循环仍然证明是真的,循环继续。有人可以帮忙吗?
【问题讨论】:
标签: c++ validation integer sstream