Author

Author- Ram Ranjeet Kumar

Thursday, April 19, 2018

How To Perform Write And Read Operation From A File In File Handling In C++




#include<iostream.h>
#include<conio.h>
#include<fstream.h>

struct stu
{
   int roll;char name[20];
 void getstu()
 {
  cout<<"\n\t Enter Roll and Name:\n";
  cout<<"Roll: ";cin>>roll;
  cout<<"\nName: ";cin>>name;
 }
 void putstu()
 {
  cout<<"\n\t Roll: "<<roll;
  cout<<"\n\t Name: "<<name;
 }
}s,s1;
void main()
{
 clrscr();
 ofstream f1;
 {
 s.getstu();
 f1.open("s.dat",ios::binary||ios::app);
 f1.write((char *)&s,sizeof(s));
 f1.close();
 }
 ifstream f2;
 {

 f2.open("s.dat",ios::binary);
 f2.read((char *)&s1,sizeof(s1));
 s1.putstu();
 }
}

No comments:

Post a Comment