C++ Iterator Library - ostreambuf_iterator



Description

It is a special output iterator that write sequentially to an stream buffer.

Declaration

Following is the declaration for std::ostreambuf_iterator.

C++11

template <class charT, class traits = char_traits<charT> >
  class ostreambuf_iterator;

Parameters

  • charT − It is a char type.

  • traits − It is a character traits.

Return value

none

Exceptions

If x somehow throws while applying the unary operator& to it, this function never throws exceptions.

Time complexity

constant for random-access iterators.

Example

The following example shows the usage of std::ostreambuf_iterator.

#include <iostream>     
#include <iterator>     
#include <string>       
#include <algorithm>    

int main () {
   std::string mystring ("Tutorailspoint.com");
   std::ostreambuf_iterator<char> out_it (std::cout); // stdout iterator

   std::copy ( mystring.begin(), mystring.end(), out_it);

   return 0;
}

Let us compile and run the above program, this will produce the following result −

Tutorailspoint.com 
iterator.htm
Advertisements