Input Stream Example

#include <iostream.h>  // cin/cout streams
#include <fstream.h>   // file streams

void main(void)
{
  int value;
  ifstream myIn;       // declare an input file stream

  // associate the output stream with a disk file.
  // this "opens" a file on the disk named datafile.in
  // we can now read from the file
  myIn.open("datafile.in", ios::in);

  myIn >> value;         // prime while loop
  while ( !myIn.eof() )  // at end of input file?
  {                     
    cout << value;    // display value on screen
    myIn >> value;    // get next value from input file
  }
  myIn.close();       // close the input file
}
If we assume that the data in datafile.in is the same as the data in the previous example (datafile.out), the output would look like this:
111248392741664525125
Note: This example assumes the input file contains only integers

Previous page
Next page

Back to Lesson 13 Index
Back to Outline