public member function
<fstream>

std::fstream::rdbuf

filebuf* rdbuf() const;
获取关联的 filebuf 对象
返回指向内部 filebuf 对象的指针。

但请注意,这不一定与当前关联的流缓冲区(由 ios::rdbuf 返回)相同。

参数



返回值

指向内部 filebuf 对象的指针。

示例

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;
}

数据竞争

访问流对象。
并发访问同一个流对象可能导致数据争用。

异常安全

强保证:如果抛出异常,流缓冲区将不会发生任何更改。

另见