Documente Academic
Documente Profesional
Documente Cultură
dat
& store store the details of 5 employees. Now
close the file & display the contents of the file onto
the screen.
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int empno;
char name[10];
int salary;
char ch;
ofstream eout;
eout.open("employee.dat",ios::out);
for(int i=1;i<6;i++)
{
cout<<"Enter the employee no:- ";
cin>>empno;
cout<<"Enter the employee name:- ";
gets(name);
cout<<"Enter the employee salary:- ";
cin>>salary;
eout<<empno<<endl<<name<<endl<<salary<<endl;
}
eout.close();
ifstream ein;
ein.open("employee.dat",ios::in);
ein.seekg(0);
for(i=1;i<6;i++)
{
ein>>empno;
ein.get(ch);
ein>>name;
ein.get(ch);
ein>>salary;
ein.get(ch);
cout<<empno<<"\n"<<name<<'\n'<<salary<<"\n";
}
ein.close();
}