I have this struct:
struct Employee
{
char VarOne[50];
unsigned int VarTwo;
double VarThree[4];
}
Then, I populate a dynamic array of this struct:
Employee* MyArray = new Employee[TheSize]; // Sorry I forgot to mention TheSize is = 5 constant
Then, I try and write the array in binary mode to a file:
// write as binary
fstream OutFileBin;
OutFileBin.open("Employee.dat", ios::binary | ios::out);
OutFileBin.write(reinterpret_cast<char *>(&MyArray), TheSize * sizeof(Employee));
OutFileBin.close();
But when I read the file in binary mode, it fails and data are junk:
// read as binary
fstream InFilebin;
InFilebin.open("Employee.dat", ios::binary | ios::in);
Employee NewArray[TheSize]; // sorry I forgot to mention TheSize is = 5 constant
InFilebin.read(reinterpret_cast<char *>(&NewArray), TheSize * sizeof(Employee));
What is that I am doing wrong?