std::ostreambuf_iterator - cppreference.com (original) (raw)

| Defined in header | | | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ------------- | | template< class CharT, class Traits = std::char_traits<CharT> > class ostreambuf_iterator : public std::iterator<std::output_iterator_tag, void, void, void, void> | | (until C++17) | | template< class CharT, class Traits = std::char_traits<CharT> > class ostreambuf_iterator; | | (since C++17) |

std::ostreambuf_iterator is a single-pass LegacyOutputIterator 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 end of file condition has been reached.

[edit] Member types

Member types iterator_category, value_type, difference_type, pointer and reference are required to be obtained by inheriting from std::iterator<std::output_iterator_tag, void, void, void, void>. (until C++17)

[edit] Member functions

(constructor) constructs a new ostreambuf_iterator (public member function) [edit]
(destructor)(implicitly declared) destructs an ostreambuf_iterator (public member function) [edit]
operator= writes a character to the associated output sequence (public member function) [edit]
operator* no-op (public member function) [edit]
operator++operator++(int) no-op (public member function) [edit]
failed tests if output failed (public member function) [edit]

[edit] Example

#include #include #include #include   int main() { std::string s = "This is an example\n"; std::copy(s.begin(), s.end(), std::ostreambuf_iterator(std::cout)); }

Output:

[edit] See also