public member function
<fstream>

std::basic_ofstream::rdbuf

basic_filebuf<char_type,traits_type>* rdbuf() const;
獲取流緩衝區
返回指向內部 basic_filebuf 物件的指標。

請注意,這不一定與當前*關聯的流緩衝區*(由 basic_ios::rdbuf 返回)相同。

引數



返回值

指向內部 basic_filebuf 物件的指標。
char_typetraits_type 是成員型別,定義為類模板引數的別名(參見 basic_ofstream 型別)。

示例

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

資料競爭

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

異常安全

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

另見