Image

Programs - C++ - File Handling

Program:


#include<fstream.h>
#include<conio.h>
void main()
{
  ofstream fout;
  fout.open("emp.cpp");
char name[20],another='y';
int age;
float bs;
  clrscr();
while(another=='y')
  {
  cout<<"enter name,age,bs\n";
  cin>>name>>age>>bs;
  fout<<name<<age<<bs;
  cout<<"wish to enter another name\n";
  cin>>another;
  }
cout<<"information stored in file";
  fout.close();
  ifstream fin;
  fin.open("emp.cpp");
while(!fin.eof())
  {
  fin>>name>>age>>bs;
  cout<<name<<age<<bs;
  }
  fin.close();
 getch();
    }