C++ streambuf - pubsync
描述
它用于同步流缓冲区并调用受保护的虚拟成员同步。
声明
以下是 std::basic_streambuf::pubsync 的声明。
int pubsync();
参数
none
返回值
它返回 streambuf 中 sync 的默认定义总是返回零,表示成功。
异常
Basic guarantee − 如果抛出异常,则流缓冲区处于有效状态。
数据竞争
它修改流缓冲区对象。
示例
在下面的例子中解释了 std::basic_streambuf::pubsync。
#include <iostream>
#include <fstream>
int main () {
std::ofstream ostr ("sample.txt");
if (ostr) {
std::streambuf * pbuf = ostr.rdbuf();
pbuf->sputn ("First sentence\n",25);
pbuf->pubsync();
pbuf->sputn ("Second sentence\n",26);
ostr.close();
}
return 0;
}

