basic_ofstream::rdbuf

To retrieve a pointer to the stream buffer.

basic_filebuf<charT, traits>* rdbuf() const;

Remarks

In order to manipulate a stream for random access or other operations you must use the streams base buffer. The member function rdbuf() is used to return a pointer to this buffer.

A pointer to basic_filebuf type is returned.

Listing: Example of basic_ofstream::rdbuf() usage:
// The file ewl-test before the operation contains:
// This is an annotated reference that contains a description
// of the Working ANSI C++ Standard Library and other
// facilities of the Embedded Warrior Library

#include <iostream>
#include <fstream> 
#include <cstdlib> 

char outFile[] = "ewl-test";

int main()
{
using namespace std;
   ofstream out(outFile, ios::in | ios::out);

   if(!out.is_open()) 
      {cout << "could not open file for output"; exit(1);}

   istream inOut(out.rdbuf());
   char ch;
   while((ch = inOut.get()) != EOF)
   {
      cout.put(ch);
   }

   out << "\nAnd so it goes...";
   out.close();
   return 0;
}

Result:

This is an annotated reference that contains a description of the Working ANSI C++ Standard Library and other facilities of the Embedded Warrior Library.

This is an annotated reference that contains a description of the Working ANSI C++ Standard Library and other facilities of the Embedded Warrior Library.

And so it goes...