#include int main( ) { ifstream in("testfile.cpp"); ofstream out("testfile.out"); out << in.rdbuf(); // copy file in.close(); out.close(); // open for reading and writing ifstream in2("testfile.out", ios::in|ios::out); ostream out2(in2.rdbuf()); cout << in2.rdbuf(); // "get' pointer is initialized to the beginning // of the file, print whole file // however, "put" pointer is at the end of file out2 << "Where does this end up?"; // append to text out2.seekp(0, ios::beg); // "put" pointer is moved to beginning // inserted text will overwrite existing text out2 << "And what about this? (overwrite existing text) "; in2.seekg(0, ios::beg); cout << in2.rdbuf(); // copy (overwrited) file getchar(); // to see the process from screen }