< cpp‎ | iterator
Revision as of 15:08, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dsc-header">

Defined in header <iterator>

<td></td> <td></td> <tr class="t-dcl ">

<td class="t-dcl-nopad">
template< class CharT, class Traits = std::char_traits<CharT>>

class ostreambuf_iterator : public std::iterator<std::output_iterator_tag,

                                                 void, void, void, void>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

std::ostreambuf_iterator is a single-pass output iterator that writes successive characters into the std::basic_streambuf object for which it was constructed. The actual write operation is performed when the iterator (whether dereferenced or not) is assigned to. Incrementing the std::ostreambuf_iterator is a no-op.

In a typical implementation, the only data members of std::ostreambuf_iterator are a pointer to the associated std::basic_streambuf and a boolean flag indicating if the the end of file condition has been reached.


Member types

Member type Definition
char_type CharT
traits_type Traits
streambuf_type std::basic_streambuf<CharT, Traits>
ostream_type std::basic_ostream<CharT, Traits>

Member functions

constructs a new ostreambuf_iterator
(public member function)
(implicitly declared)
destructs an ostreambuf_iterator
(public member function)
writes a character to the associated output sequence
(public member function)
(public member function)
(public member function)
tests if output failed
(public member function)

Member types

Member type Definition
value_type void
difference_type void
pointer void
reference void
iterator_category std::output_iterator_tag

Note: before C++17, these member types are required to be obtained by inheriting from std::iterator<std::output_iterator_tag,void,void,void,void>.


#include <string>
#include <algorithm>
#include <iterator>
#include <iostream>
int main()
    std::string s = "This is an example\n";
    std::copy(s.begin(), s.end(), std::ostreambuf_iterator<char>(std::cout));


This is an example

See also

Template:cpp/iterator/dcl list istreambuf iteratorTemplate:cpp/iterator/dcl list ostream iterator