函式
<ios> <iostream>

std::unitbuf

ios_base& unitbuf (ios_base& str);
插入後重新整理緩衝區
str 流設定 unitbuf “格式”標誌。

當設定 unitbuf 標誌時,在每次插入操作後都會重新整理關聯的緩衝區。

可以使用 nounitbuf 操縱符取消設定此標誌,不再強制每次插入後重新整理。

對於標準流,unitbuf 標誌在初始化時未設定

引數

str
格式標誌受影響的流物件。
因為此函式是一個操縱符,它被設計為在不帶引數的情況下,與流上的插入 (<<) 和提取 (>>) 操作結合使用(見下例)。

返回值

引數 str

示例

1
2
3
4
5
6
7
8
9
10
// modify unifbuf flag
#include <ios>         // std::unitbuf
#include <fstream>     // std::ofstream

int main () {
  std::ofstream outfile ("test.txt");
  outfile << std::unitbuf <<  "Test " << "file" << '\n';  // flushed three times
  outfile.close();
  return 0;
}

資料競爭

修改 str。對同一個流物件的併發訪問可能導致資料競爭。

異常安全

基本保證:如果丟擲異常,str 處於有效狀態。

另見