home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Info / TeachU14 / SAMS / Code / Day04 / writefil.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-08  |  725 b   |  32 lines

  1. #include <condefs.h>
  2. #include <fstream.h>
  3. #include <conio.h>
  4.  
  5. #pragma hdrstop
  6.  
  7. int main(int, char **)
  8. {
  9.   char buff[81];
  10.   cout << "Creating File..." << endl;
  11.   ofstream outfile("test.dat");
  12.   if (!outfile) return 0;
  13.   cout << "Writing File..." << endl;
  14.   for (int i=0;i<10;i++) {
  15.     outfile << "This is line #" << (i + 1) << endl;
  16.   }
  17.   outfile.close();
  18.   cout << "Opening File for Input..." << endl;
  19.   ifstream infile("test.dat");
  20.   if (!infile) return 0;
  21.   cout << "Reading File..." << endl << endl;
  22.   while (!infile.eof()) {
  23.     infile.getline(buff, sizeof(buff));
  24.     cout << buff << endl;
  25.   }
  26.   infile.close();
  27.   cout << endl << "Press any key to continue...";
  28.   getch();
  29.   return 0;
  30. }
  31.  
  32.