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?

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.

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.