C++迭代器库 - ostreambuf_iterator



描述

这是一个特殊的输出迭代器,用于顺序写入流缓冲区。

声明

以下是std::ostreambuf_iterator的声明。

C++11

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

参数

  • charT − 字符类型。

  • traits − 字符特性。

返回值

异常

如果在对x应用一元运算符&时,x以某种方式抛出异常,则此函数不会抛出异常。

时间复杂度

对于随机访问迭代器,时间复杂度为常数。

示例

以下示例演示了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;
}

让我们编译并运行上述程序,这将产生以下结果:

Tutorailspoint.com 
iterator.htm
广告
© . All rights reserved.