Namespaces
Variants
Views
Actions

std::istream_iterator::istream_iterator

From cppreference.com
< cpp‎ | iterator‎ | istream iterator
Revision as of 12:10, 31 March 2013 by Cubbi (Talk | contribs)

Template:ddcl list begin <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
istream_iterator();
constexpr istream_iterator();
</td>

<td > (1) </td> <td >
(since C++11, only if T is literal type) </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
istream_iterator(istream_type& stream);
</td>

<td > (2) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
istream_iterator(const istream_iterator& other) = default;
</td>

<td > (3) </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

1) Constructs the end-of-stream iterator.
2) Initializes the iterator and stores the address of stream in a data member. Optionally, performs the first read from the input stream to initialize the cached value data member (although it may be delayed until the first access)
3) Constructs a copy of other. If T is a literal type, this copy constructor is a trivial copy constructor.

Parameters

stream - stream to initialize the istream_iterator with
other - another istream_iterator of the same type

Examples

#include <iostream>
#include <iterator>
#include <algorithm>
#include <sstream>
int main()
{
    std::istringstream stream("1 2 3 4 5");
    std::copy(
        std::istream_iterator<int>(stream),
        std::istream_iterator<int>(),
        std::ostream_iterator<int>(std::cout, " ")
    );
}

Output:

1 2 3 4 5