Having a stream's streambuf persist beyond stream's destruction?
问题 Is it possible to have a stream's streambuf persist after the destruction of its originating stream's destruction? streambuf* f() { ifstream my_stream; // ... return my_stream.rdbuf(); } void g() { streambuf *s = f(); // ... ifstream my_new_stream; my_new_stream.rdbuf( s ); } I.e., I want the pointer to the streambuf object returned by f() to remain valid even after my_stream goes out of scope. At some later time, I want to set some other stream's streambuf to the saved streambuf . Is this