using namespace std;
//cin demo with exception detection and quit
int main(void)
{
int n = 0;
char c;
while(cin)
{
cout << "Enter a int(q to quit): ";
cin >> n;
if(!cin)
{
cin.clear();
c=cin.peek();
if(c=='q')
break;
else
{
cout << "Oops try again\n";
cin.ignore(5000,'\n');
}
}
}
return 0;
}
No comments:
Post a Comment