Extract X and Y Coordinates from String
Asked Answered
L

1

10

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

Lioness answered 13/7, 2012 at 11:13 Comment(1)
You could use sscanf docs.roxen.com/pike/7.0/tutorial/strings/sscanf.xmlRoche
R
1
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;
}
Rosenstein answered 13/7, 2012 at 11:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.