从String中提取X和Y坐标

时间:2012-07-13 11:13:45

标签: string box2d extract cocos2d-x

我遇到了从CCString中提取b2vec2坐标的问题,这些坐标来自cocos2dx和box2d。

我尝试过使用strtk,但我无法让它工作

任何帮助都会很棒。

由于

字符串的布局是“x,y x,y x,y” 我想将x和y放入b2vec2

的数组中

1 个答案:

答案 0 :(得分: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;
}