public member function
<fstream>

std::ofstream::rdbuf

filebuf* rdbuf() const;
獲取流緩衝區
返回指向內部 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
// copy a file using file stream buffers
#include <fstream>      // std::filebuf, std::ifstream, std::ofstream
#include <cstdio>       // EOF

int main () {
  std::ifstream ifs ("test.txt");
  std::ofstream ofs ("copy.txt");

  std::filebuf* inbuf  = ifs.rdbuf();
  std::filebuf* outbuf = ofs.rdbuf();

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

  ofs.close();
  ifs.close();

  return 0;
}

資料競爭

訪問流物件。
併發訪問同一個流物件可能導致資料爭用。

異常安全

強保證:如果丟擲異常,流緩衝區將不會發生任何更改。

另見