I am trying to read structures from a file using c++, I am using end of file function. But I am having a problem, my last structure is displayed twice. I dont know why is this so.
void display_account(account a) {
ifstream fin;
fin.open("bank account.dat",ios::binary);
if (fin.fail()) {
cout << "error in opening file.... FILE DONT EXIST ...OR YOU HAVENT CREATED ANY ACCOUNT YET" << endl;
exit(1);
}
else {
while (!fin.eof()) {
fin.read((char*)&a, sizeof(a))
cout << "\nAccount number : " << a.AccNumber << endl;
cout << "Account title : " << a.name << endl;
cout << "State name is : " << a.state << endl;
cout << "Zip code is : " << a.zip << endl;
cout << "Telephone no is : " << a.telp << endl;
cout << "Account balence is : " << a.balence << endl;
cout << "last date of payment is : " << a.paymentdt << endl;
}
}
fin.close();
system("pause");
}