• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <iterator>

    std::istream_iterator::operator*

    const T& operator*() const;
    

    概要

    イテレータを間接参照する。 読み込み済みの値を返す。

    戻り値

    operator++()で入力ストリームから読み込まれ、メンバ変数として保持されている値を返す。

    #include <iostream>
    #include <iterator>
    #include <sstream>
    
    int main()
    {
      std::stringstream ss;
      ss << 1 << std::endl
         << 2 << std::endl
         << 3;
    
      std::istream_iterator<int> it(ss); // 入力ストリームオブジェクトへの参照を渡す
      std::istream_iterator<int> last;   // デフォルト構築。終端値として使用する
    
      for (; it != last; ++it) {
        int result = *it;
        std::cout << result << std::endl;
      }
    }
    

    出力

    1
    2
    3
    

    参照