最終更新日時:
が更新

履歴 編集

function
<locale>

std::num_put::put

public:
  iter_type put(iter_type out, ios_base& str, char_type fill, bool val) const;               // (1) C++98
  iter_type put(iter_type out, ios_base& str, char_type fill, long val) const;               // (2) C++98
  iter_type put(iter_type out, ios_base& str, char_type fill, long long val) const;          // (3) C++11
  iter_type put(iter_type out, ios_base& str, char_type fill, unsigned long val) const;      // (4) C++98
  iter_type put(iter_type out, ios_base& str, char_type fill, unsigned long long val) const; // (5) C++11
  iter_type put(iter_type out, ios_base& str, char_type fill, double val) const;             // (6) C++98
  iter_type put(iter_type out, ios_base& str, char_type fill, long double val) const;        // (7) C++98
  iter_type put(iter_type out, ios_base& str, char_type fill, const void* val) const;        // (8) C++98

概要

数値・真偽値・ポインタを書式化して、出力イテレータoutへ出力する。

  • (1) : boolを出力する
  • (2), (3) : 符号付き整数型 (long, long long) を出力する
  • (4), (5) : 符号なし整数型 (unsigned long, unsigned long long) を出力する
  • (6), (7) : 浮動小数点数型 (double, long double) を出力する
  • (8) : ポインタ (const void*) を出力する

fillは、str.width()による幅指定を満たすために使用される埋め文字である。

戻り値

#include <iostream>
#include <sstream>
#include <locale>
#include <iterator>

int main()
{
  std::ostringstream oss;
  const auto& facet = std::use_facet<std::num_put<char>>(oss.getloc());

  facet.put(std::ostreambuf_iterator<char>{oss}, oss, ' ', 42L);
  oss << ' ';
  facet.put(std::ostreambuf_iterator<char>{oss}, oss, ' ', 3.14);

  std::cout << oss.str() << std::endl;
}

出力

42 3.14

バージョン

言語

  • C++98

関連項目