C++ ifstream get()

Description

C++ ifstream get()

#include <fstream.h>
#include <stdlib.h>
ifstream fp;/*ww w  .  java 2 s  .c  o  m*/
void main()
{
   char filename[12]; // Holds user's filename.
   char in_char;      // Input character.
   cout << "What is the name of the file you want to see? ";
   cin >> filename;
   fp.open(filename, ios::in);
   if (!fp)
   {
      cout << "\n\n*** That file does not exist ***\n";
      exit(0);    // Exit program.
   }
   while (fp.get(in_char))
   {
      cout << in_char;
   }
   fp.close();
   return;
}



PreviousNext

Related