Here's a more C++ idiomatic solution:
void readObj(const std::string& fName,
std::vector<Vector3>& tempVertex,
std::vector<Face3>& tempFaces)
{
std::ifstream file(fName);
std::string line;
while (std::getline(file, line))
{
std::istringstream iss(line);
char type;
if (iss >> type)
{
if (type == 'v')
{
Vector3 v;
if (iss >> v.x >> v.y >> v.z)
tempVertex.push_back(v);
}
else if (type == 'f')
{
Face3 f;
if (iss >> f.a >> f.b >> f.c)
tempFaces.push_back(v);
}
}
}
}
References:
As for your current code (as posted in the question) a big problem is this:
strcmp(lineHeader, "v ")
/* here -------------^ */
The string lineHeader
only contains the "v"
or "f"
, not the trailing space.