int main()
{
int choice=0;
while(1){
cout << "请输入你的选择:";
cin >> choice;
if(!cin.good() ) //判断输入类型是否正确
{
cout << "输入错误,请重新输入!" << endl;
cin.clear();
cin.ignore(); //清空缓存区
system("pause");
system("cls");
continue;
}
switch (choice)
{
case 0:
break;
case 1:
break;
case 2:
break;
default:
cout << "输入错误,请重新输入:" << endl;
break;
}
}
return 0;
}
判断输入类型是否正确
最新推荐文章于 2023-12-13 22:47:41 发布