PROGRAM TO PERFORM INPUT AND OUTPUT OPERATIONS ON FILES

/*PROGRAM TO PERFORM INPUT AND OUTPUT OPERATIONS ON FILES*/

#include<iostream.h>

#include<fstream.h>

#include<conio.h>

#include<stdlib.h>

class file_io

{

ofstream outfile;

char fname[10],line[100],ch;

int i;

public:

void input();

void output();

};

void file_io::input()

{

cout<<“WRITING INFORMATION TO FILE\n”;

cout<<“Enter the file name to be opened? “;

cin>>fname;

outfile.open(fname);

cout<<“Information to be stored on file is: “<<endl;

cout<<“I am student of CGC landran “<<endl;

cout<<“i have taken MCA course”<<endl;

outfile<<“I am student of CGC landran \n”;

outfile<<“I have taken MCA course”;

outfile.close();

}

void file_io::output()

{

cout<<“READING INFORMATION FROM FILE\n”;

ifstream infile;

char fname[10],ch;

cout<<“Enter file name: “;

cin>>fname;

infile.open(fname);

if(infile.fail())

{

cerr<<“No such file exist\n”;

getch();

exit(1);

}

while(!infile.eof())

{

ch=(char)infile.get();

cout<<ch;

}

infile.close();

}

void main()

{

file_io f1;

clrscr();

f1.input();

f1.output();

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *