C++ Fstream 库 - rdbuf 函数
描述
它返回一个指向内部 filebuf 对象的指针。
声明
以下是 fstream::rduf 的声明。
C++11
filebuf* rdbuf() const;
返回值
它返回一个指向内部 filebuf 对象的指针。
异常
Strong guarantee − 如果抛出异常,则流缓冲区中没有变化。
数据竞争
它访问流对象。
并发访问同一个流对象可能会导致数据竞争。
示例
在下面的示例中解释了 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;
}

