ofstream::rdbuf
filebuf* rdbuf ( ) const;
ofstream
  cplusplus.com  

Get the filebuf object associated with the stream.
  Returns the filebuf object associated with the stream.

Parameters.

none
 

Return Value.
  A pointer to the filebuf object associated with the stream.
  Notice that this pointer is never NULL, even if the buffer is not associated with any file. It is a pointer to the private filebuf object.

Example.

// copy a file using associated buffer's members
#include <fstream>
using namespace std;

int main () {
  char ch;
  ifstream infile;
  ofstream outfile;
  filebuf *inbuf, *outbuf;

  infile.open ("test.txt");
  outfile.open ("copy.txt");

  inbuf=infile.rdbuf();
  outbuf=outfile.rdbuf();

  ch = inbuf->sgetc();
  while ( ch != EOF)
  {
    outbuf->sputc (ch);
    ch= inbuf->snextc();
  }

  outfile.close();
  infile.close();

  return 0;
}
The example opens an input and an output file, then gets the pointers to their respective file buffers and performs operations on them to make a character-by-character copy of the input file.

Basic template member declaration ( basic_ofstream<charT,traits> ):
basic_filebuf<charT,traits> * rdbuf () const;

See also.
  ios::rdbuf
  filebuf class, ofstream class


© The C++ Resources Network, 2001