• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <chrono>

    std::chrono::from_stream

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

    概要

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

    効果

    • パラメータfmtで指定されたフォーマットフラグを使用して、入力を解析し、tpに代入する
    • いずれのフラグもdurationに影響しないものである場合、dには値ゼロが代入される
    • タイムゾーンフォーマット"%Z"が指定され、解析が成功した場合、パラメータabbrevが非ヌルである場合に*abbrevにタイムゾーン名が代入される
    • タイムゾーンとしてUTC時間からのオフセット時間 (日本なら"+0900") を意味するフォーマット"%z"が指定され、解析が成功した場合、パラメータoffsetが非ヌルである場合に*offsetにその値が代入される

    戻り値

    return is;
    

    #include <iostream>
    #include <chrono>
    #include <sstream>
    
    namespace chrono = std::chrono;
    
    int main()
    {
      {
        std::stringstream ss;
        ss << "3";
    
        chrono::seconds sec{0};
        chrono::from_stream(ss, "%S", sec);
    
        std::cout << sec << std::endl;
      }
      {
        std::stringstream ss;
        ss << "+0900 JST";
    
        chrono::seconds sec{3};
        std::string abbrev;
        chrono::minutes offset{0};
        chrono::from_stream(ss, "%S", sec, &abbrev, &offset);
    
        std::cout << sec << std::endl;
        std::cout << abbrev << std::endl;
        std::cout << chrono::floor<chrono::hours>(offset) << std::endl;
      }
    }
    

    出力

    3s
    0s
    JST
    9h
    

    バージョン

    言語

    • C++20

    処理系

    関連項目