Name
ostream_iterator class template — Output iterator to write items to an ostream
Synopsis
template <typename T, typename charT = char, typename traits = char_traits<charT> > class ostream_iterator : public iterator<output_iterator_tag,void,void,void,void> { public: typedef charT char_type; typedef traits traits_type; typedef basic_ostream<charT,traits> ostream_type; ostream_iterator(ostream_type& s); ostream_iterator(ostream_type& s, const charT* delimiter); ostream_iterator(const ostream_iterator<T,charT,traits>& x); ~ostream_iterator( ); ostream_iterator<T,charT,traits>& operator=(const T& value); ostream_iterator<T,charT,traits>& operator*( ); ostream_iterator<T,charT,traits>& operator++( ); ostream_iterator<T,charT,traits>& operator++(int); };
The ostream_iterator
class
template wraps an output iterator around an output stream (instance
of basic_ostream
), making the
stream appear to be a sequence of items, each of type T
. For example, suppose you have a vector
of data. You can print the data, one number per line, by using an
ostream_iterator
:
std::vector<int> data; . . . // Acquire data. std::copy(data.begin( ), data.end( ), std::ostream_iterator(std::cout, "\n"));
The following are the member functions of ostream_iterator
:
-
ostream_iterator
(ostream_type& stream)
ostream_iterator
(ostream_type&
stream, const
charT*
delimiter)
ostream_iterator
(const ostream_iterator<T,charT,traits>&
x)
Prepares to write items to
stream
. Ifdelimiter
is present, it will be written after each ...
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.