get two input at the same time and check for cin.fail()

is there any way to detect cin.fail for 2 inputs?

1
2
3
4
5
6
7
8
9
10
11
while(true)
        {
            cin >> row >> col;
            if (cin.fail()|| a[row][col]!='*')
            {
                cout << "bad input. Please reenter." << endl;
                cin.clear();
                cin.ignore(1000000,'\n');
            }
            else break;
        }


this doesn't work for it.. it only works for one input..
How does it not work?
keep looping "bad input" even though I enter a correct value..
Try this (exact same code that works for me. Maybe the '*' is your problem? )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

int main(){
   int row, col;
   while(true)
   {
      std::cin >> row >> col;
      if (std::cin.fail())
      {
         std::cout << "bad input. Please reenter.\n";
         std::cin.clear();
         std::cin.ignore(1000000,'\n');
      }
      else break;
   }
}
then it keep buffering for my input..

buffer when I put only integers(let's say 2039), it buffers until I put F7(row should be a character,should be "A6","F10"), then after I enter a character and an integer )it displayed "bad input" again, if I only enter a character first it buffers until I input an int(let's say, I cin f, then it waits until I input 10), which is working...
Last edited on
Oh, row is a char and col is an int? Well, 2 in 2039 is a perfectly valid char. If you want it to fail, add an isalpha(row) condition. Though how do you expect a[row][col] to work then ?
Last edited on
So no any alternative way to solve it?
There is nothing wrong with the code you pasted (syntactically). Are you sure that your array is initialized to '*'s?

Also, you should check the inputs for domain.
the '*' is the initialized value to the array, after inserting row and column the particular array will change to a 'X' or 'O'. I want to detect any faulty values inserted or inserting row and column which is already 'X' or 'O' which should not be changed anymore..
At this point we need to see more code.
Problem solved by using my own method. Thanks for the replies.
Topic archived. No new replies allowed.