std::ostreambuf_iterator::ostreambuf_iterator

来自cppreference.com
ostreambuf_iterator( streambuf_type* buffer );
(1)
ostreambuf_iterator( ostream_type& stream );
(2)
1) 构造迭代器,将私有的 streambuf_type* 成员设为 buffer 并将 failed() 位设为 false 。若 buffer 是空指针则行为未定义。
2)ostreambuf_iterator(stream.rdbuf())

[编辑] 参数

stream - 将关联其 rdbuf() 到此迭代器的输出流
buffer - 此迭代器要访问的输出流缓冲

[编辑] 异常

(无) (C++11 前)
noexcept 规定:  
noexcept
  
(C++11 起)

[编辑] 示例

#include <iostream>
#include <fstream>
#include <iterator>
int main()
{
    std::basic_filebuf<char> f;
    f.open("test.txt", std::ios::out);
 
    std::ostreambuf_iterator<char> out1(&f);
 
    std::ostreambuf_iterator<wchar_t> out2(std::wcout);
 
    *out1 = 'a';
    *out2 = L'a';
}