I am writting a code which read a binary file with c++. At first, the code was tested in gcc 7.3 in Linux and it works. Now, I am testing the code with Visual Studio 2015 in Windows 7. after reading the 9th record from the file, eof() value becomes true and it breaks the loop while still hundreads of record remains.
I am not sure why the code behavior is different.
#include <iostream>
#include <fstream>
int main(int argc, char** argv)
{
std::ifstream ifs;
ifs.open("test.bin");
while(!ifs.eof())
{
unsigned date;
char time;
float lat;
float lon;
float hs;
float tp;
float dp;
float vw;
float dw;
ifs.read(reinterpret_cast<char*>(&date), sizeof(unsigned));
ifs.read(reinterpret_cast<char*>(&time), sizeof(char));
ifs.read(reinterpret_cast<char*>(&lat), sizeof(float));
ifs.read(reinterpret_cast<char*>(&lon), sizeof(float));
ifs.read(reinterpret_cast<char*>(&hs), sizeof(float));
ifs.read(reinterpret_cast<char*>(&tp), sizeof(float));
ifs.read(reinterpret_cast<char*>(&dp), sizeof(float));
ifs.read(reinterpret_cast<char*>(&vw), sizeof(float));
ifs.read(reinterpret_cast<char*>(&dw), sizeof(float));
}
ifs.close();
std::cout << "end of file" << std::endl;
return 0;
}