home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C18 / Iofile.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  838 b   |  31 lines

  1. //: C18:Iofile.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Reading & writing one file
  7. #include "../require.h"
  8. #include <iostream>
  9. #include <fstream>
  10. using namespace std;
  11.  
  12. int main() {
  13.   ifstream in("Iofile.cpp");
  14.   assure(in, "Iofile.cpp");
  15.   ofstream out("Iofile.out");
  16.   assure(out, "Iofile.out");
  17.   out << in.rdbuf(); // Copy file
  18.   in.close();
  19.   out.close();
  20.   // Open for reading and writing:
  21.   ifstream in2("Iofile.out", ios::in | ios::out);
  22.   assure(in2, "Iofile.out");
  23.   ostream out2(in2.rdbuf());
  24.   cout << in2.rdbuf();  // Print whole file
  25.   out2 << "Where does this end up?";
  26.   out2.seekp(0, ios::beg);
  27.   out2 << "And what about this?";
  28.   in2.seekg(0, ios::beg);
  29.   cout << in2.rdbuf();
  30. } ///:~
  31.