flush
描述 (Description)
它用于刷新输出流缓冲区并使关联的流缓冲区与其受控输出序列同步。
声明 (Declaration)
以下是std :: ostream :: flush的声明。
ostream& flush();
参数 (Parameters)
没有
返回值 (Return Value)
它返回ostream对象(* this)。
异常 (Exceptions)
Basic guarantee - 如果抛出异常,则对象处于有效状态。
数据竞争 (Data races)
修改流对象。
例子 (Example)
在下面的例子中解释了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;
}