ios::rdbuf
streambuf* rdbuf ( ) const;
streambuf* rdbuf ( streambuf* sb );
ios
  cplusplus.com  

Get/set the streambuf object associated with the stream.
  The first syntax returns the streambuf object associated with the stream.
  The second syntax associates the stream with streambuf object sb and returns the streambuf object previously associated with the stream.

Parameters.

sb
A pointer to the streambuf object to associate the stream with.

Return Value.
  A pointer to the streambuf object associated 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 and later assign 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.
  ios class


© The C++ Resources Network, 2001