I am having a slight issue when reading from a file in C++, the reason for the function is to find a line that has the characters v and a space at the beginning of it.
It is finding line correctly, but when trying read numbers from the file, it is always outputting 0.
Here is the code for the function
Model::Model(std::string fileName) {
std::ifstream reader;
reader.open(fileName);
float temp1 = 0, temp2 = 0, temp3 = 0;
if (reader.is_open()) {
std::string line;
while (reader.eof() != true) {
getline(reader, line);
if (line.substr(0, 2) == "v ") {
reader >> temp1 >> temp2 >> temp3;
std::cout << temp1 << " | " << temp2 << " | " << temp3 << std::endl;
}
}
}
else {
std::cerr << "Error opening the file at path " + fileName;
}
}
It is reading from the file fine, and is printing all well, but the temp variables are staying at 0 for some reason.
Anyone know how to fix this? Or any ideas as to why this is happening?
My only idea is that the stream for some reason is getting bad input, but that wouldn't make too much sense.
Any help appreciated!