C++ C++。obj解析器面
将.obj文件的面值传递给向量C++ C++。obj解析器面,c++,parsing,.obj,C++,Parsing,.obj,将.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”之后的值),然后简单地将值输出到终端。我相信您可以修改它以从文件中读
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
例2
注意行boost::char\u分隔符sep(“/”)代码>这是将被计为有效分隔符的所有标记的说明符。在您的情况下,将其更改为boost::char\u 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;
}
}
在第二个示例中,我使用字符串流从整个输入中读取单个字符串,并使用基本检查来查看第一个字符是否为“f”。这个例子也应该适合您的需要。您必须按照本文中的解释拆分字符串:[1]:如果您被允许使用boost,您可以继续使用它的漂亮标记器,不幸的是,我们不允许使用boost
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
#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