The following causes a bug because file.eof() apparently doesn’t return true until a read past the end of the file. How should I be doing this?
std::ifstream file("something.stuff", std::ios::in|std::ios::binary);
while(!file.eof())
{
double x, y, z;
file.read(reinterpret_cast<char*>(&x), sizeof(x)); // Do I need to check if(file) after every read?
file.read(reinterpret_cast<char*>(&y), sizeof(y));
file.read(reinterpret_cast<char*>(&z), sizeof(z));
// Do something with xyz
}
You can just check it after all the reads, unless you intend to do something with partial data, so: