public member function
<locale>

std::num_put::put

iter_type put (iter_type out, ios_base& str, char_type fill, bool val) const;iter_type put (iter_type out, ios_base& str, char_type fill, long val) const;iter_type put (iter_type out, ios_base& str, char_type fill, unsigned long val) const;iter_type put (iter_type out, ios_base& str, char_type fill, double val) const;iter_type put (iter_type out, ios_base& str, char_type fill, long double val) const;iter_type put (iter_type out, ios_base& str, char_type fill, const void* val) const;
iter_type put (iter_type out, ios_base& str, char_type fill, bool val) const;iter_type put (iter_type out, ios_base& str, char_type fill, long val) const;iter_type put (iter_type out, ios_base& str, char_type fill, unsigned long val) const;iter_type put (iter_type out, ios_base& str, char_type fill, double val) const;iter_type put (iter_type out, ios_base& str, char_type fill, long double val) const;iter_type put (iter_type out, ios_base& str, char_type fill, const void* val) const;iter_type put (iter_type out, ios_base& str, char_type fill, long long val) const;iter_type put (iter_type out, ios_base& str, char_type fill, unsigned long long val) const;
格式化數值
val 格式化為字元序列並寫入 out
此過程使用透過 str 物件傳遞的格式化選項(透過其 ios_base::fmtflags 值及其內嵌的 locale),以及 fill 作為 填充字元

該函式將格式化操作產生的字元寫入由 out 指向的序列。

函式返回一個指向輸出序列中最後一個寫入元素之後一個位置的迭代器。

在內部,此函式僅呼叫虛擬受保護成員 do_put,該成員預設按照 格式指定 的格式生成序列,該格式對應於 val 引數的型別,並考慮 str格式標誌欄位寬度。該函式使用 str 中選定的區域設定(透過 facet numpunct)來獲取格式詳細資訊,並在必要時(使用 ctype::widen)來擴充套件字元。

引數

下可用的型別
指向表示為字元序列的第一個字元的迭代器。
序列的長度應足以包含整個表示式。
成員型別 iter_type 是 facet 的迭代器型別(定義為 num_put 的第二個模板引數 OutputIterator 的別名)。預設情況下,它是 ostreambuf_iterator,允許從 basic_ostream 物件隱式轉換。
str
派生自 ios_base 的類物件(通常是 *輸出流物件*)。它僅用於獲取格式資訊。
fill
填充字元:當結果需要填充到 *欄位寬度* 時,*填充字元* 用於輸出插入操作。
成員型別 char_type 是 facet 的字元型別(定義為 num_put 的第一個模板引數 charT 的別名)。
val
要格式化的值。

返回值

最後寫入字元之後的序列中的下一個字元。
成員型別 iter_type 是 facet 的迭代器型別(定義為 num_put 的第二個模板引數 OutputIterator 的別名)。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// num_put example
#include <iostream>       // std::cout
#include <locale>         // std::locale, std::num_put, std::use_facet

int main ()
{
  std::cout.width(10);    // set field width to 10 characters

  std::use_facet<std::num_put<char> >(std::cout.getloc()).put
    (std::cout, std::cout, '0', 3.14159265);

  std::cout << '\n';

  return 0;
}

可能的輸出

0003.14159


資料競爭

該物件被訪問。
成功時,指向 out 的陣列將被修改。

異常安全

如果丟擲異常,*facet 物件* 沒有任何更改,儘管某些引數可能會受到影響。

另見