Namespaces
Variants
Views
Actions

std::ostream_iterator<T,CharT,Traits>::ostream_iterator

From cppreference.com
 
 
Iterator library
Iterator concepts
Iterator primitives
Algorithm concepts and utilities
Indirect callable concepts
Common algorithm requirements
Utilities
Iterator adaptors
Stream iterators
Iterator customization points
Iterator operations
(C++11)
(C++11)
Range access
(C++11)(C++14)
(C++11)(C++14)
(C++17)(C++20)
(C++14)(C++14)
(C++14)(C++14)
(C++17)
(C++17)
 
 
ostream_iterator(ostream_type& stream, const CharT* delim)
(1)
ostream_iterator(ostream_type& stream)
(2)
1) Constructs the iterator with stream as the associated stream and delim as the delimiter.
2) Constructs the iterator with stream as the associated stream and a null pointer as the delimiter.

[edit] 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

[edit] 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