the program runs successfully but the final output comes out in the form of an infinite loop...please help
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
struct emp
{
int eno;
char name[20],desig[20];
float sal;
}e;
void main()
{
clrscr();
ofstream f1;
f1.open("emp.dat",ios::app|ios::binary);
char ch='y';
while(f1)
{
if(ch=='y'||ch=='Y')
{
cout<<"Enter the name"<<endl;
gets(e.desig);
cout<<"Enter the salary"<<endl;
cin>>e.sal;
cout<<"Enter the designation"<<endl;
gets(e.desig);
f1.write((char*)&e,sizeof(emp));
cout<<"Do you want to enter more records??"<<endl;
cin>>ch;
}
else
f1.close();
}
ifstream f2;
f2.open("emp.txt",ios::binary);
cout<<"The File after appending is"<<endl;
f2.read((char*)&e,sizeof(emp));
while(!f2.eof())
{
cout<<e.desig<<" "<<e.name<<" "<<e.sal;
f2.read((char*)&e,sizeof(emp));
f2.eof();
}
f2.close();
getch();
}
also could you plz tell me the use of
f2.read((char*)&e,sizeof(emp));
f1.write((char*)&e,sizeof(emp));
our teacher didnt really explain its significance