They are constructed from a basic_ostream object, to which they become associated, so that whenever an assignment operator (=) is used on the ostream_iterator (even when dereferenced) it inserts a new element into the stream.
Optionally, a delimiter can be specified on construction. This delimiter is written to the stream after each element is inserted.
It is defined with an operation similar to:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
Template parameters
- T
- Element type for the iterator: The type of elements inserted into the stream
- charT
- First template parameter for the basic_ostream: The type of elements the stream manages (char for ostream).
- traits
- Second template parameter for the basic_ostream: Character traits for the elements the stream manages.
Member functions
- constructor
- ostream_iterator objects are constructed from an ostream object, and optionally a delimiter.
A copy constructor also exists to copy objects of the same type. - operator=
- Writes an element into the stream. If delimiter was specified on construction, it is also inserted after the value.
- operator*
- Does nothing. Returns a reference to the object.
- operator++
- Does nothing. Returns a reference to the object.
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Output:
10, 20, 30, 40, 50, 60, 70, 80, 90, |
See also
| istream_iterator | Istream iterator (class template) |
| OutputIterator | Output iterator category |
| ostream | Output Stream (class) |
