Search This Blog

Friday 3 June 2016

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


No comments:

Post a Comment

How do I crack the GSOC in the field of machine learning?

How do I crack the GSOC in the field of machine learning? Working as a student at Google Summer of Code demands for your dedication an...