pubsync
描述 (Description)
它用于同步流缓冲区并调用受保护的虚拟成员同步。
声明 (Declaration)
以下是std :: basic_streambuf :: pubsync的声明。
int pubsync();
参数 (Parameters)
没有
返回值 (Return Value)
它返回streambuf中默认的sync定义,总是返回零,表示成功。
异常 (Exceptions)
Basic guarantee - 如果抛出异常,则流缓冲区处于有效状态。
数据竞争 (Data races)
它修改了流缓冲区对象。
例子 (Example)
在下面的示例中解释了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;
}