std::ostreambuf_iterator<CharT,Traits>::ostreambuf_iterator
< cpp | iterator | ostreambuf iterator
(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'; }