detect cin.fail with two inputs
Aug 17, 2011 at 3:27am Aug 17, 2011 at 3:27am UTC
I have a function that detects cin.fail..
1 2 3 4 5 6 7 8 9 10 11 12
int n;
while (true ){
cin >> n;
if (cin.fail()|| n<=0)
{
cout << "Bad input. Please reenter." << endl;
cin.clear();
cin.ignore(1000000,'\n' );
}
else break ;
}
return n;
But this only works for one input, so is there any way to accept two input and detect error?
The two input is an array with a[row][col], which I want to detect cin.fail for row and col
Aug 17, 2011 at 3:49am Aug 17, 2011 at 3:49am UTC
std::cin, std::cout, std::cerr are global objects that presented in a single instance
Aug 21, 2011 at 9:59am Aug 21, 2011 at 9:59am UTC
Solved by using my own method. Topic closed, thanks for reply.
Topic archived. No new replies allowed.