Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract X and Y Coordinates from String

I'm having a problem with extracting b2vec2 coordinates from a CCString these are from cocos2dx and box2d.

I have tried using strtk but i could not get it to work

Any help would be great.

Thanks

The Layout of the string is "x,y x,y x,y" i want to put the x and y's into an array of b2vec2

like image 998
user1523362 Avatar asked Jul 13 '12 11:07

user1523362


1 Answers

string s = "12,4 4,5 6,3";

istringstream is(s);
while (is.good())
{
    int x, y;
    char comma;
    is >> x >> comma >> y;

    cout << x << ", " << y << endl;
}
like image 156
Andrew Avatar answered Oct 28 '22 20:10

Andrew