We have been assigned to make a program for a bank using data file handling, as our project.
I am having some trouble at this point... the last object written in the file is printed twice and I've no clue as to why.
Case for display:
file.open("Records.dat", ios::in | ios::binary);
if (!file)
cout<<"\nCan not open file.";
else
{
file.seekg (ios::beg);
while (!file.eof())
{
file.read( (char*) &rec, sizeof (account) );
rec.display();
}
}
file.close();
And my display function for the class:
void display () {
cout<<"\nAccount number: "<<number;
cout<<"\nName: "<<holder;
cout<<"\nAddress: "<<add;
cout<<"\nPhone number: "<<phno;
cout<<"\nBalance: "<<bal<<endl;
}
I don't see anything wrong in the display function, so I'm guessing it has something to do with the eof() function. But I still can't rectify it :/
Any bright ideas?