Namespaces
Variants
Views
Actions

std::ostream_iterator::operator=

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

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

<td class="t-dcl-nopad">
ostream_iterator& operator=( const T& value )
</td>

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

Inserts value into the associated stream, then inserts the delimiter, if one was specified at construction time.

If out_stream is the private member pointer to the associated std::basic_ostream and delim is the pointer to the first character in the delimiter, the effect is equivalent to

*out_stream << value;
if(delim != 0)
    *out_stream << delim;
return *this;

Contents

Parameters

value - the object to insert

Return value

*this

Notes

T can be any class with a user-defined operator<<

Example

#include <iostream>
#include <iterator>
 
int main()
{
    std::ostream_iterator<int> i1(std::cout, ", ");
    *i1++ = 1; // usual form, used by standard algorithms
    *++i1 = 2;
    i1 = 3; // neither * nor ++ are necessary
    std::ostream_iterator<double> i2(std::cout);
    i2 = 3.14;
}

Output:

1, 2, 3, 3.14