'cin array, while loop 2 times

int a[20], b[20];

int input;

int asize = 0;

cout << "Please enter array A: ";
while (cin >> input)
{
    a[asize] = input;

    ++asize;
}

int input2;
int bsize = 0;

cout << "Please enter array B: ";
while (cin >> input2)
{
    b[bsize] = input2;

    ++bsize;
}

Example: I wanted user to input = 1 2 3 q for a input = 2 3 4 6 7 q for b so the array for a will be 1 2 3 and b will be 2 3 4 6 7 but the loop just stopped at the first while loop, i dont know why, can any one make suggestion?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source