C++ fstream 庫 - rdbuf 函式



描述

它返回指向內部 filebuf 物件的指標。

宣告

以下是 fstream::rduf 的宣告。

C++11

filebuf* rdbuf() const;

返回值

它返回指向內部 filebuf 物件的指標。

異常

強保證 - 如果丟擲異常,流緩衝區沒有任何更改。

資料競爭

  • 它訪問流物件。

  • 同時訪問同一個流物件可能會導致資料競爭。

示例

下面的例子解釋了 fstream rdbuf 函式。

#include <fstream>
#include <cstdio>

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;
}
fstream.htm
廣告
© . All rights reserved.