Namespaces
Variants

std:: time_put

From cppreference.net
ヘッダーで定義 <locale>
template <

class CharT,
class OutputIt = std:: ostreambuf_iterator < CharT >

> class time_put ;

クラステンプレート std::time_put は日付と時刻の書式設定ルールをカプセル化します。I/Oマニピュレータ std::put_time は、I/Oストリームのロケールの std::time_put ファセットを使用して、 std::tm オブジェクトのテキスト表現を生成します。

cpp/locale/time base cpp/locale/locale/facet std-time put-inheritance.svg

継承図

標準ライブラリによって提供されることが保証されていない std::time_put 特殊化(下記参照)の場合、その put() および do_put() の動作は指定通りであることが保証されません。

目次

翻訳の説明: - 「Contents」を「目次」に翻訳しました - C++関連の専門用語(Specializations、Nested types、Data members、Member functions、Protected member functions、Example、See also)は原文のまま保持しました - HTMLタグ、属性、クラス名、IDなどは一切変更していません - 数値や構造は完全に保持されています

特殊化

標準ライブラリは以下の特殊化を提供することが保証されています(これらは あらゆるロケールオブジェクトで実装が必須 とされています):

定義済みヘッダー <locale>
std :: time_put < char > 日付と時刻のナロー文字列表現を作成する
std :: time_put < wchar_t > 日付と時刻のワイド文字列表現を作成する

さらに、標準ライブラリは以下の型要件を満たすすべての特殊化を提供することも保証されています:

  • CharT char wchar_t のいずれかであり、
  • OutputIt LegacyOutputIterator の要件を満たさなければならない。

ネスト型

定義
char_type CharT
iter_type OutputIt

データメンバ

メンバー 説明
std::locale::id id [static] facet の識別子

メンバー関数

新しい time_put ファセットを構築する
(public member function)
time_put ファセットを破棄する
(protected member function)
do_put を呼び出す
(public member function)

プロテクテッドメンバー関数

[virtual]
日付/時刻をフォーマットして出力ストリームに書き込む
(仮想保護メンバー関数)

#include <codecvt>
#include <ctime>
#include <iomanip>
#include <iostream>
int main()
{
    std::time_t t = std::time(nullptr);
    std::wbuffer_convert<std::codecvt_utf8<wchar_t>> conv(std::cout.rdbuf());
    std::wostream out(&conv);
    out.imbue(std::locale("ja_JP.utf8"));
    // this I/O manipulator std::put_time uses std::time_put<wchar_t>
    out << std::put_time(std::localtime(&t), L"%A %c") << '\n';
}

出力:

水曜日 2011年11月09日 12時32分05秒

関連項目

指定されたロケールのシステム提供の std::time_put を表す
(クラステンプレート)
入力文字シーケンスから日時値を std::tm に解析する
(クラステンプレート)
(C++11)
指定されたフォーマットに従って日時値をフォーマットして出力する
(関数テンプレート)