C++.obj语法分析器面
C++ .obj parser face
艰难地将.obj文件的面值传递给向量。
f 5/1/1 1/2/1 4/3/1
f 5/1/1 4/3/1 8/4/1
f 3/5/2 7/6/2 8/7/2
这是我需要存储的,但是
f 5//1 1//1 4//1
f 5//1 4//1 8//1
f 3//2 7//2 8//2
有时候可能是这样,我不知道该怎么解决这个问题,谢谢。
这里有一个使用boost::tokenizer
的示例,我使用stdin
读取输入('f'之后的所有值),然后我简单地将值输出到终端。我相信您可以将其修改为从文件中读取,并将值放置在需要的位置。
示例1
#include <iostream>
#include <string>
#include <boost/tokenizer.hpp>
using namespace std;
using namespace boost;
void ParseFace(const string& face);
int main(){
cout << "Input a string: " << endl;
string s;
getline(cin,s);
ParseFace(s);
return 0;
}
void ParseFace(const string& face){
boost::char_separator<char> sep(" /");
boost::tokenizer<boost::char_separator<char> > tokens(face, sep);
for(tokenizer<boost::char_separator<char> >::iterator beg=tokens.begin(); beg!=tokens.end();++beg){
cout << *beg << "n";
}
}
样本输出:
Input a string:
3/5/2 7/6/2 8/7/2
3
5
2
7
6
2
8
7
2
Input a string:
5//1 1//1 4//1
5
1
1
1
4
1
示例2
请注意行boost::char_separator<char> sep(" /");
这是将被视为有效分隔符的所有标记的说明符。在您的情况下,将其更改为boost::char_separator<char> sep("/");
(无空格),然后简单地读取字符串,这样可能会更方便:
#include <iostream>
#include <string>
#include <boost/tokenizer.hpp>
#include <sstream>
using namespace std;
using namespace boost;
void ParseFace(istringstream& _input);
int main(){
cout << "Input a string: " << endl;
string s;
getline(cin,s);
istringstream input(s);
char isFace = 'v';
input >> isFace;
if (!input.fail()){
if (isFace == 'f')
ParseFace(input);
}
return 0;
}
void ParseFace(istringstream& _input){
string nextVal;
_input >> nextVal;
while(!_input.fail()){
cout << "Next set: " << endl;
boost::char_separator<char> sep("/");
boost::tokenizer<boost::char_separator<char> > tokens(nextVal, sep);
for(tokenizer<boost::char_separator<char> >::iterator beg=tokens.begin(); beg!=tokens.end();++beg){
cout << *beg << "n";
}
_input >> nextVal;
}
}
样本输出:
Input a string:
f 5/1/1 1/2/1 4/3/1
Next set:
5
1
1
Next set:
1
2
1
Next set:
4
3
1
Input a string:
f 5//1 1//1 4//1
Next set:
5
1
Next set:
1
1
Next set:
4
1
在第二个示例中,我使用字符串流从整个输入中读取单个字符串,并使用基本检查来查看第一个字符是否为"f"。这个例子也应该适合你的需要。
相关文章:
- 1d 智能指针不适用于语法 (*)++
- 使用 gperftools 的堆分析器来分析 libc malloc
- 在手写语法分析器中翻译语法文件
- 我们是否可以使用 g++ 编译代码通过 Solaris Studio 的性能分析器进行性能分析?
- 手工编写的递归上升语法分析器中的递归左递归
- GLSL 语法错误:"in"分析错误
- C++.obj语法分析器面
- 无序时分析逗号分隔的语法
- 递归下降分析和语法树
- 将qi::十六进制语法分析器限制为2个字符
- 编译错误,带有boost::spirit语法分析器
- Sequential Or语法分析器a||b
- 用于从文件填充类的词法分析器/解析器的语法规则
- 词汇和语法分析器软件
- 在气的精神中回滚替代语法分析器的变化
- 在递归下降语法分析器中避免了递归算法中的stackoverflow
- 使用Alternative语法分析器提高spirit较差的性能
- Lexer和来自EBNF的C++语法分析器
- 助推::精神::气.如何将内联语法分析器表达式转换为独立语法,以及如何解压缩它们生成的元组
- 如何编写SFINAE来测试语法分析器规则