我需要通过cin验证用户输入我的代码如下:
#include"iostream"
using namespace std;
int main()
{
int choice = 0;
while(1)
{
cout<<"ENTER your choice a value between 0 to 2"<<endl;
cin>>choice;
// Here i need some logic which will work like "choice" can be only
// Integer and within the range i.e. 0 to 2 and if it is not
// satisfy condition then ask user to input again
switch(choice)
{
case 0:
exit(1);
break;
case 1:
fun();
break;
case 2:
fun1();
break;
default: cout<<"Please enter a valid value"<<endl;
break;
}
}
return 0;
}