This: while(in.eof()!= 1)
is probably why it is always shows the last object read in twice. You shouldn't use the return value of eof() to control performance of a loop body for that very reason. Lot's of folks have bookmarked a reference to a technical explanation for why that's so, but I've never really understood it all that well, so I won't try to explain it. I just know this type of problem can develop when you use that type of approach. To try to fix it, try this:
while(in.read((char *)&st,sizeof(st)))
{
st.showData();
}
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
Find the length of file. Divide the length of file by size of an object.
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241