std::ostream_iterator (3) - Linux Manuals
std::ostream_iterator: std::ostream_iterator
NAME
std::ostream_iterator - std::ostream_iterator
Synopsis
Defined in header <iterator>
template< class T,
class CharT = char,
class Traits = std::char_traits<CharT> > (until C++17)
class ostream_iterator : public std::iterator<std::output_iterator_tag,
void, void, void, void>
template< class T,
class CharT = char, (since C++17)
class Traits = std::char_traits<CharT>>
class 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.
In a typical implementation, the only data members of std::ostream_iterator are a pointer to the associated std::basic_ostream and a pointer to the first character in the delimiter string.
When writing characters, std::ostreambuf_iterator is more efficient, since it avoids the overhead of constructing and destructing the sentry object once per character.
Member types
Member type Definition
char_type CharT
traits_type Traits
ostream_type std::basic_ostream<CharT, Traits>
Member functions
constructor (public member function)
destructor (public member function)
operator= (public member function)
operator* (public member function)
operator++ (public member function)
operator++(int)
Member types
Member type Definition
value_type void
difference_type void
pointer void
reference void
iterator_category std::output_iterator_tag
These member types are required to be obtained by inheriting from std::iterator<std::output_iterator_tag, void, void, void, void>. (until C++17)
Example
// Run this code
Output:
See also
ostreambuf_iterator (class template)
istream_iterator (class template)
std::experimental::ostream_joiner An output iterator that writes successive elements into an output stream, separating adjacent elements with a delimiter
(library fundamentals TS v2)