本文介绍了来自 3D .obj 文件的 C++ 字符串标记化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 C++ 还很陌生,一直在寻找一种将数据从这一行中提取出来的好方法.

I'm pretty new to C++ and was looking for a good way to pull the data out of this line.

我可能需要标记的示例行是

A sample line that I might need to tokenise is

f 11/65/11 16/70/16 17/69/17

我有一种标记化方法,可以将字符串拆分为由可能有用的字符串分隔的向量

I have a tokenisation method that splits strings into a vector as delimited by a string which may be useful

static void Tokenise(const string& str, vector& tokens, const string& delimiters = " ")

我能想到的唯一方法是用"作为分隔符标记,从结果向量中删除第一项,然后单独标记每个部分.有没有一种好方法可以同时完成所有这些操作?

The only way I can think of doing it is to tokenise with " " as a delimiter, remove the first item from the resulting vector, then tokenise each part by itself. Is there a good way to do this all in one?

推荐答案

我看到问题被标记为 C++,但最简单的方法是使用 scanf

I see the question is tagged as C++ but the absolutely easiest way to do this is with scanf

int indices[3][3];
sscanf(buffer, "f %d/%d/%d %d/%d/%d %d/%d/%d", &indices[0][0], &indices[0][1],...);

这篇关于来自 3D .obj 文件的 C++ 字符串标记化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 15:12
查看更多