Program to perform read and write operations on a file.

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
class a{
public:
void writeFile()
{
ofstream myfile ("example.txt");
  if (myfile.is_open())
  {
    myfile << "This is iView Blogger.\n";
    myfile << "iView-The Way i-View!!.\n";
    myfile.close();
    cout<<"File Saved!"<<endl;
  }
  else
    cout << "Unable to open file";
}
void readFile()
{
string line;
  ifstream myfile ("example.txt");
  if (myfile.is_open())
  {
    while ( getline (myfile,line) )
    {
      cout << line << '\n';
    }
    myfile.close();
  }
  else
  cout << "Unable to open file";
}
void Quit ()
{
    cout << "\tThanks For iView-ing!!\n\t\tExiting" << endl;
    cout<<"\n/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/";
    exit (-1);
}


};
class start:public a
{
public:
void startq(){
int opt;
cout<<"\n\n1.Write"<<endl<<"2.Read"<<endl<<"3.Exit"<<endl<<"Enter your choice : ";
cin>>opt;
switch(opt)
{
case 1:
writeFile();
startq();

case 2:
readFile();
startq();

case 3:
Quit();

default:
cout<<"error"<<endl;
startq();
}}
};
int main()
{
start ab;
ab.startq();
}

Output:


Comments

Popular posts from this blog

Program to illustrate the concept of templates.

To create an html file to implement the concept of margin, padding using cascading style sheets.

To configure the IP address for a computer connected to LAN