C++ Ostream 库 - flush
描述
它用于刷新输出流缓冲区并将关联的流缓冲区与其受控输出序列同步。
声明
以下是 std::ostream::flush 的声明。
ostream& flush();
参数
none
返回值
它返回 ostream 对象 (*this)。
异常
Basic guarantee − 如果抛出异常,则对象处于有效状态。
数据竞争
修改流对象。
示例
在下面的例子中解释了 std::ostream::flush。
#include <fstream>
int main () {
std::ofstream outfile ("test.txt");
for (int n=0; n<100; ++n) {
outfile << n;
outfile.flush();
}
outfile.close();
return 0;
}

