Reputation: 31
I have a simplest possible code which has to accept and reprint two numbers. It works well for any separating symbol I've tried (space, + ,etc.) except (!) the comma.
cout << "Enter x & y coordinates: ";
cin >> x;
cin >> y;
cout << "Coordinates are (" << x << "," << y << ")" << endl;
2+2 outputs (2,2)
2.2 waits for the second number
but 2,2 doesn't prompt for a second number and just outputs (2,0). Why is this happening? Where does the stuff after the comma go?
Upvotes: 1
Views: 88
Reputation: 218268
It works well for any separating symbol I've tried (space, + ,etc.) except (!) the comma.
In fact, no.
2+2
are 2 numbers: 2
and +2
(as number can begin with +
or -
)In other cases, std::cin >> y
would fail, and set cin
in error state, and set y to 0.
Upvotes: 3