Namespaces
Variants
Views
Actions

std::ostream_iterator::ostream_iterator

From cppreference.com
< cpp‎ | iterator‎ | ostream iterator
Revision as of 15:13, 2 November 2012 by P12bot (Talk | contribs)

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

<tr class="t-dcl ">

<td >
ostream_iterator(ostream_type& stream, const CharT* delim)
</td>

<td > (1) </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 >
ostream_iterator(ostream_type& stream)
</td>

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

1) Constructs the iterator with the private ostream_type* member initialized with &stream and the private delimiter pointer initialized with delim.

2) Constructs the iterator with the private ostream_type* member initialized with &stream and the private delimiter pointer initialized with null pointer value.

Parameters

stream - the output stream to be accessed by this iterator
delim - the null-terminated character string to be inserted into the stream after each output

Example

#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
    std::ostream_iterator<int> i1(std::cout, ", ");
    std::fill_n(i1, 5, -1);
    std::ostream_iterator<double> i2(std::cout);
    *i2++ = 3.14;
}

Output:

-1, -1, -1, -1, -1, 3.14