我正在尝试解析一个文件。我目前正在使用以下代码,但希望用基于sstream的解决方案来替换它
unsigned int vertexIndex[3], uvIndex[3], normalIndex[3];
const char* cstring = line.c_str();
int matches = sscanf(cstring, "f %d/%d/%d %d/%d/%d %d/%d/%d\n", &vertexIndex[0], &uvIndex[0], &normalIndex[0], &vertexIndex[1], &uvIndex[1], &normalIndex[1], &vertexIndex[2], &uvIndex[2], &normalIndex[2]);当我尝试以下操作时,我得到了意想不到的结果
std::stringstream f(line);
f >> vertexIndex[0] >> uvIndex[0] >> normalIndex[0] >> vertexIndex[1] >> uvIndex[1] >> normalIndex[1] >> vertexIndex[2] >> uvIndex[2] >> normalIndex[2];我肯定我误解了流的使用。任何帮助都是很棒的!
发布于 2016-08-10 23:26:01
这只是一种简单的缺乏理解。对我的特殊问题的解决方案是:
std::stringstream ss(line.substr(2));
char throwaway;
for (int i = 0; i < 3; i++){
ss >> vertexIndex[i] >> throwaway >> uvIndex[i] >> throwaway >> normalIndex[i];
}我的下一个问题是,为什么下面的方法不起作用?
ss.ignore(std::numeric_limits<std::streamsize>::max(), '/');
ss >> vertexIndex[i] >> uvIndex[i] >> normalIndex[i];https://stackoverflow.com/questions/38874200
复制相似问题