对于我的地图创建算法,用户在数据文件中输入如下数字:
0, 3, 0, 0
14, 2, 26, 5这些数字表示瓦片的特定纹理的id,以便生成单元/世界数据。我已经制作了去掉逗号的部分,使它看起来像这样:
0 3 0 0
14 2 26 5我遇到的问题是,我想将某些数字推入一个字符串流中,这样就可以对它们进行解析,并为它们提供正确的纹理。某些数字彼此之间有1个空格,因此很容易将其推入字符串流中,但是如何从一个数字跳转到另一个数字,以便以相同的顺序将其推入字符串流?
谢谢!
发布于 2014-04-05 06:13:02
可能是这样的:
std::string snumbers = ...; // your input string with no commas
std::stringstream sstream(snumbers);
std::vector<std::string> items;
std::string item;
while(sstream >> item) items.push_back(item);
const size_t N = items.size() / 2; // this is the number of pairs you have
std::cout << "pair 0: " << items[0] << ", " << items[N] << std::endl;
std::cout << "pair 1: " << items[1] << ", " << items[1+N] << std::endl;
...https://stackoverflow.com/questions/22873816
复制相似问题