#include <iostream>
#include <string>
using namespace std;
{
cin.clear(); //清除错误
char c;
while(cin >> c) //查看字符
{
if(isdigit(c)) //字符是数字
{
cin.unget(); //把字符放回去
return;
}
}
{
int n = 0;
while(true)
{
if(cin >> n) return n;
cout << "\n Sorry, that not an integer, please try again . \n";
skip_to_int();
}
#include <string>
using namespace std;
{
if(cin.fail()) //输入不是数字,发生错误{
cin.clear(); //清除错误
char c;
while(cin >> c) //查看字符
{
if(isdigit(c)) //字符是数字
{
cin.unget(); //把字符放回去
return;
}
}
}
cerr << "\nBad Input ! \n" << endl;
}
//输入数字
{
int n = 0;
while(true)
{
if(cin >> n) return n;
cout << "\n Sorry, that not an integer, please try again . \n";
skip_to_int();
}
}
//输入low到high之间的数字,tip:提示ÿ