以下导致错误,因为file.eof()
显然true
直到文件末尾读取才返回。我应该怎么做?
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
}