ios::rdbuf | public member function |
streambuf* rdbuf ( ) const; streambuf* rdbuf ( streambuf* sb ); |
Get/set the associated stream buffer
The first syntax returns the stream buffer object associated with the stream.
The second syntax associates the stream with sb and returns the stream buffer object previously associated with the stream. In this case, the buffer's control state is set to goodbit as if a call to member clear().
Parameters
- sb
- A pointer to the stream buffer object to associate the stream with.
Return Value
A pointer to the stream buffer object associated with the stream before the call.Example
// redirecting cout's output #include <iostream> #include <fstream> using namespace std; int main () { streambuf *psbuf; ofstream filestr; filestr.open ("test.txt"); psbuf = filestr.rdbuf(); cout.rdbuf(psbuf); cout << "This is written to the file"; filestr.close(); return 0; } |
This example uses both function syntaxes to first get a pointer to a file's streambuf object and later assigns it to cout.
Basic template member declaration
( basic_ios<charT,traits> )
basic_streambuf<charT,traits> * rdbuf () const;
basic_streambuf<charT,traits> * rdbuf ( basic_streambuf<charT,traits> sb );
|
See also
streambuf | Base buffer class for streams (class) |