从字符串中提取X和Y坐标

10

我在从Cocos2d-x和Box2D中提取b2vec2坐标时遇到了问题。

我尝试过使用strtk,但是无法让它正常工作。

希望能得到任何帮助。

谢谢。

字符串的格式为“x,y x,y x,y”,我想将x和y放入一个b2vec2数组中。


你可以使用 sscanf http://docs.roxen.com/pike/7.0/tutorial/strings/sscanf.xml - iforce2d
1个回答

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;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接