std::ostreambuf_iterator<CharT,Traits>::ostreambuf_iterator

来自cppreference.com
 
 
迭代器库
迭代器概念
迭代器原语
迭代器适配器
流迭代器
迭代器定制点
迭代器操作
(C++11)
(C++11)
范围访问
(C++11)(C++14)
(C++11)(C++14)
(C++17)(C++20)
(C++14)(C++14)
(C++14)(C++14)
(C++17)
(C++17)
 
 
(1)
ostreambuf_iterator( streambuf_type* buffer ) throw();
(C++11 前)
ostreambuf_iterator( streambuf_type* buffer ) noexcept;
(C++11 起)
(2)
ostreambuf_iterator( ostream_type& stream ) throw();
(C++11 前)
ostreambuf_iterator( ostream_type& stream ) noexcept;
(C++11 起)
1) 构造迭代器,将私有的 streambuf_type* 成员设为 buffer 并将 failed() 位设为 false 。若 buffer 是空指针则行为未定义。
2)ostreambuf_iterator(stream.rdbuf())

[编辑] 参数

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

[编辑] 示例

#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';
}