I'm working on a very simple parser for wavefront *.obj files.
The general idea is to read each line of the file and then based on the start keyword parse that line accordingly, but I have some troubles with it:
bool Model::loadModel(const char* fileName)
{
std::ifstream file(fileName, std::ios::binary);
if(file.fail())
return false;
std::string line;
std::string type;
std::istringstream istr;
while(std::getline(file, line))
{
istr.str(line);
istr>>type;
.
.
.
For example the file I have has in its first line:
g Dragon
so in "type" I have a "g" stored. The problem is that when I read the next line
v -0.136296 0.0938588 -0.0307373
istr is apparently initialized but after the >> operation type still has "g".
The loop continues and that "g" value never changes.
I have some other *.obj files that I can read perfectly, the only difference is that in the debuger I see a '\r' at the end of all the lines.
Is this character needed to extract data from a istringstream?