'|' is not seen as an integer as far as user input goes. So when you enter an '|' it will cause cin to be put in a failure state.
1 2 3 4
|
while (cin >> x >> y)
{
}
|
is equivalent to:
while ((cin >> x) >> y)
The >> operator returns the state of the stream
after the extraction. So when cin >> x happens, if it is successful, cin will be a good state. cin >> x returns cin itself to allow for operator chaining. So then cin >> y happens, and the final state of the stream is then converted into a boolean to be used with the while loop.
The problem with
1 2
|
while(cin.good()) {
cin >> x >> y;
|
Is that you aren't doing failure checking after the cin >> x >> y operations.
while (cin >> x >> y) returns the state of the stream after attempting to process x and y.
In other words,
while (cin >> x >> y) { }
is saying "while we are successfully able to extract two integers from the stream and put them into the x and y variables".
If you wan the user to be able to enter both an integer or a non-numeric character like '|', you need to parse the input as a string first, and then convert it to an integer.
By the way, when posting code, please also post the "#include" part of your code and anything else above main. This will let your program compile without us having to manually add to it.