cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : ios : rdbuf
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
IOstream Library
manipulators
classes:
· filebuf
· fstream
· ifstream
· ios
· iostream
· ios_base
· istream
· istringstream
· ofstream
· ostream
· ostringstream
· streambuf
· stringbuf
· stringstream
objects:
· cerr
· cin
· clog
· cout
types:
· fpos
· streamoff
· streampos
· streamsize
ios
· ios::ios
· ios::~ios
member functions:
· ios::bad
· ios::clear
· ios::copyfmt
· ios::eof
· ios::exceptions
· ios::fail
· ios::fill
· ios::good
· ios::imbue
· ios::init
· ios::narrow
· ios::operator!
· ios::operator void*
· ios::rdbuf
· ios::rdstate
· ios::setstate
· ios::tie
· ios::widen

-

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)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us