Employee e;//object of class employee
fstream myfile;
myfile.open("Client_Details.dat",ios::in|ios::out|ios::binary);
myfile.seekg(0,ios::beg);
if(!myfile)
cout<<"Can't Open The File"<<endl;
else
{
while(!myfile.eof())
{
myfile.read(reinterpret_cast<char*>(&e),sizeof(Employee));
}
//this is the //other code i used ,,,because this isn't working
//while(myfile.read(char*)&e,sizeof(e))
//{
// e.printEmployeeDetails();
//}
}
1. What do you mean "isn't working"?
2. Can we see the class definition of Employee (is Employee a plain-old-data class)?
3. How are you writing the Employees to the file?
if(!myfile) is the same as if(!myfile.good()). That condition will be true if any of the error flags have been set. In our case, if the file was not opened, then an error flag will be set so this is a valid check.