#include <iostream> #include <fstream> using namespace std; ofstream file( "rdbuf.txt" ); streambuf *x = cout.rdbuf( file.rdbuf( ) ); cout << "test" << endl; cout << "test2" << endl; cout.rdbuf(x);