0

so the user enters a string of coordinates like "(1,2) (3,4) (5,6) etc..." and I'm trying to use istringstream to pull out each number and put it into an integer value. This is what I've got so far:

string S1, temp;
int num1=0, tempX, tempY;
cin.ignore(15,'\n');
getline(cin,S1);

num1=S1.find("(");
S1.erase(S1.begin(),S1.begin()+num1+1);
cout << S1 << endl;

istringstream ss(S1);
ss >> tempX;
cout << tempX << endl;
num1=S1.find(",");
S1.erase(S1.begin(),S1.begin()+num1+1);

So far it only grabs the first number, and I'm at a loss of what to do next. Any suggestions?

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by thisischris
0

You might want to consider to first break the problem into set of points (x,y). Then extract and convert each set of points to numbers.

0

Okay, so I extract each point into a vector of strings. Can someone show me how to copy a segment of a string into a separate string?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.