public member function
<fstream>

std::basic_fstream::rdbuf

basic_filebuf<char_type,traits_type>* rdbuf() const;
Get stream buffer
Returns a pointer to the internal basic_filebuf object.

Notice however, that this is not necessarily the same as the currently associated stream buffer (returned by basic_ios::rdbuf).

Parameters

none

Return Value

A pointer to the internal basic_filebuf object.
char_type and traits_type are member types defined as aliases of the class template parameters (see basic_fstream types).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// copy a file using file stream buffers
#include <fstream>      // std::filebuf, std::fstream
#include <cstdio>       // EOF

int main () {
  std::fstream src,dest;
  src.open ("test.txt");
  dest.open ("copy.txt");

  std::filebuf* inbuf  = src.rdbuf();
  std::filebuf* outbuf = dest.rdbuf();

  char c = inbuf->sbumpc();
  while (c != EOF)
  {
    outbuf->sputc (c);
    c = inbuf->sbumpc();
  }

  dest.close();
  src.close();

  return 0;
}


Data races

Accesses the stream object.
Concurrent access to the same stream object may cause data races.

Exception safety

Strong guarantee: if an exception is thrown, there are no changes in the stream buffer.

See also