There is a STL <ios>
library function
streambuf* std::basic_ios::rdbuf (streambuf* sb);
This function can be used to change the stream buffer associated with a stream. If you use this, it returns a pointer to the streambuf that was previously in use. It's not clear who 'owns' the pointer or what its lifetime is. The standard (27.5.5.3/5) simply says
Returns: the previous value of
rdbuf()
.
which is not very informative. Are there any guarantees about how long this pointer is valid for? Should the calling code delete
the pointer once it's done with it?