Hey guys I’m having trouble with some code I’m writing for a .obj model parser.
Here’s the code that’s causing the problem:
std::istringstream iss(line.substr(1));
std::copy(
std::istream_iterator<float>(iss),
std::istream_iterator<float>(),
std::back_inserter<std::vector<float>>(model.chunks.back().vectices)
);
It’s basically taking a string passed as a argument like this:
v -5.000000 -1.000000 1.000000
Then gets the substring from it so it’s left with only this:
-5.000000 -1.000000 1.000000
Finally I use std::copy and get each set of numbers from within the string:
vertices[0] = -5.000000
vertices[1] = -1.000000
vertices[2] = 1.000000
Anyways the main problem here is that I’m getting an error from this line of code:
std::back_inserter<std::vector<float>>(model.chunks.back().vectices));
It says “expected token ‘;’ got float” my code still compiles and run’s flawlessly though.
Although if I replace the floats in that code with std::string’s I don’t get the error anymore.
std::copy(
std::istream_iterator<std::string>(iss),
std::istream_iterator<std::string>(),
std::back_inserter<std::vector<std::string>>(model.chunks.back().vectices)
);
I’m using Qt Creator so could this possibly be just a IDE error? Any help would be greatly appreciated!
It might be that your IDE doesn’t understand the
>>in your template specification. Older versions of the C++ standard required that you put a space in between each>as in> >, otherwise it could be confused with the right shift operator>>. So: