Let's say that I have an input that is a pair of coordinate points: x,y. Two numbers, and a comma in between (no space). How would I separate the two numbers into two different integer variables?
For example:
1 2
Input: 12,10
X coordinate is 12 and Y coordinate is 10
#include <iostream>
usingnamespace std;
int main()
{
char comma;
int x, y;
cout << "Input X, Y: ";
cin >> x >> comma >> y;
cout << "The x coordinate is " << x << " and the y coordinate is " << y << '\n';
}
Input X, Y: 10,12
The x coordinate is 10 and the y coordinate is 12