• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <chrono>

    std::chrono::from_stream

    namespace std::chrono {
      template <class charT, class traits, class Alloc = std::allocator<charT>>
      std::basic_istream<charT, traits>&
        from_stream(std::basic_istream<charT, traits>& is,
                    const charT* fmt,
                    year& y,
                    basic_string<charT, traits, Alloc>* abbrev = nullptr,
                    minutes* offset = nullptr);   // (1) C++20
    }
    

    概要

    フォーマット指定して入力ストリームからyearオブジェクトに入力する。

    効果

    • パラメータfmtで指定されたフォーマットフラグを使用して、入力を解析し、yに代入する
    • 有効な年の解析に失敗した場合、is.setstate(ios_base::failbit)が呼び出され、パラメータyは変更されない
    • タイムゾーンフォーマット"%Z"が指定され、解析が成功した場合、パラメータabbrevが非ヌルである場合に*abbrevにタイムゾーン名が代入される
    • タイムゾーンとしてUTC時間からのオフセット時間 (日本なら"+0900") を意味するフォーマット"%z"が指定され、解析が成功した場合、パラメータoffsetが非ヌルである場合に*offsetにその値が代入される

    戻り値

    isを返す

    #include <cassert>
    #include <sstream>
    #include <chrono>
    
    namespace chrono = std::chrono;
    
    int main()
    {
      {
        std::stringstream ss;
        ss << "2020";
    
        chrono::year y;
        chrono::from_stream(ss, y, "%y");
        assert(y == chrono::year{2020});
      }
      {
        std::stringstream ss;
        ss << "0123";
    
        chrono::year y;
        chrono::from_stream(ss, y, "%4Y");
        assert(y == chrono::year{123});
      }
    }
    

    出力

    バージョン

    言語

    • C++20

    処理系

    関連項目