WAP to display contents of a file using get() function.

//WAP to display contents of a file using get() function.
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
int main()
{
      system("cls");
      char ch;
      ifstream fin;     //create input stream
      fin.open("marks.dat", ios::in);     //open file
      if(!fin)    //if fin stores zero i.e., false value
      {
            cout<<"Cannot open file!!\n";
            return 1;
      }
      while(fin)
      {     fin.get(ch);      //read a character
            cout<<ch;   //display the character
      }
      fin.close();
      return 0;
}
OUTPUT


Comments

Popular posts from this blog

WAP using a class to store price list of 5 items and to print the largest prices as well as the sum of all prices.

WAP that obtains the rotation factor and rotates the array as per it.

WAP to get roll numbers and marks of the student of a class (get from the user) and store these details into a file called Marks.dat