std::ostreambuf_iterator
<iterator>
class ostreambuf_iterator
class ostreambuf_iterator;
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
iterator_category
std::output_iterator_tag
value_type
void
pointer
void
reference
void
char_type
CharT
traits_type
Traits
streambuf_type
std::basic_streambuf <CharT, Traits>
ostream_type
std::basic_ostream <CharT, Traits>
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>.
[edit] Member functions
[edit] Example
#include <algorithm> #include <iostream> #include <iterator> #include <string> int main() { std::string s = "This is an example\n"; std::copy (s.begin(), s.end(), std::ostreambuf_iterator<char>(std::cout )); }
Output:
This is an example