rdbuf

To retrieve a pointer to the stream buffer.

  basic_streambuf<charT, traits>* rdbuf() const;
  basic_streambuf<charT, traits>* rdbuf
     (basic_streambuf<charT, traits>* sb);
  
Remarks

To manipulate a stream for random access or synchronization it is necessary to retrieve a pointer to the streams buffer. The function rdbuf() allows you to retrieve this pointer. The rdbuf() function that takes an argument has the post-condition of sb is equal to rdbuf().

Returns a pointer to basic_streambuf object.

Listing: Example of rdbuf() usage:
#include <iostream>
struct address {

   int number;

   char street[40];

} addbook;

int main()

{

using namespace std;

   cout << "Enter your street number: ";

   cin >> addbook.number;

   cin.rdbuf()->pubsync(); // buffer flush

   cout << "Enter your street name: "; 

   cin.get(addbook.street, 40);

   cout << "Your address is: "

         << addbook.number << " " << addbook.street;

   return 0;

}

Result:

  Enter your street number: 1313
  Enter your street name: Mockingbird Lane
  Your address is: 1313 Mockingbird Lane