Section
std::ostream_iterator
std::ostream_iterator is a single-pass LegacyOutputIterator that writes successive objects of type T into the std::basic_ostream object for which it was constructed, using operator«. Optional delimiter string is written to the output stream after every write operation. The write operation is performed when the iterator (whether dereferenced or not) is assigned to. Incrementing the std::ostream_iterator is a no-op.
# Declarations
template< class T,
class CharT = char,
class Traits = std::char_traits<CharT> >
class ostream_iterator
: public std::iterator<std::output_iterator_tag, void, void, void, void>
(until C++17)
template< class T,
class CharT = char,
class Traits = std::char_traits<CharT> >
class ostream_iterator;
(since C++17)
# Example
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
int main()
{
std::istringstream str("0.11 0.22 0.33 0.44");
std::partial_sum(std::istream_iterator<double>(str),
std::istream_iterator<double>(),
std::ostream_iterator<double>(std::cout, ", "));
std::cout << '\n';
}