//The out put of following code gives last record twice. What is wrong. Please help.
Code:
#include <iostream>
#include <conio.h>
#include <fstream>
#include <cstdlib>
using namespace std;
struct abc
{
char code[5],name[15],address[20];
int pay;
};
main()
{
abc rec;
char op;
int i=0;
ifstream rrr("employees.dat",ios::in | ios::binary);
if(!rrr)
{
cerr<<("File opening error")<<endl;
getche();
exit(1);
}
while(!rrr.eof()){
rrr.read((char*)&rec,sizeof(struct abc));
cout<<rec.code<<"\t"<<rec.name<<"\t"<<rec.address<<"\t"<<rec.pay<<endl;
}
rrr.close();
getche();
return(0);
}
Comment