File handling I/O in C++ Using oop

#include<iostream>
#include<fstream>
#include<string.h>
#include<conio.h>
using namespace std;
class easy
{
public :
char ch;
char name[100]; char str[200];
void enty ()
{
cout<<“first create file name to save your content \n”;
cin>>name;
cout<<” creating file content \n”;
cin>>str;

ofstream obj; //making object of class ofstream
obj.open(name); // create open “eg.easy.txt” for writing data
// write to a file
obj<<str<< “\n”;
obj<<“this is an example for I/O file handling in C++,” << endl;
obj.close(); // close the file
// return 0;
}
};

class displ: public easy
{
public :
int disply()
{

    ifstream obj(name); //open file foe reading
 cout<<“This data read from file named :(“<<name<<“)”<<“\n”;
          while (obj.get(ch))
          cout<<ch;
          obj.close(); // close the file
      return 0;
}
};
int main()
{
displ obj;
obj.enty();
clrscr();
obj.disply();
getch();
}

Leave a Comment