std::ostreambuf_iterator
来自cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev ">
</tbody><tbody>
</tbody>
| 在标头 <iterator> 定义
|
||
template< class CharT, class Traits = std::char_traits<CharT> > class ostreambuf_iterator : public std::iterator<std::output_iterator_tag, void, void, void, void> |
(C++17 前) | |
template< class CharT, class Traits = std::char_traits<CharT> > class ostreambuf_iterator; |
(C++17 起) | |
std::ostreambuf_iterator 是单趟输出迭代器,写入相继元素到为之创建迭代器的 std::basic_streambuf 对象。实际写操作在赋值给迭代器(无论是否解引用)时进行。自增 std::ostreambuf_iterator 是无操作。
典型实现中,std::ostreambuf_iterator 仅有的数据成员是指向关联 std::basic_streambuf 的指针,和指示是否抵达文件尾条件的布尔标志。
成员类型
| 成员类型 | 定义 | ||||
iterator_category
|
std::output_iterator_tag
| ||||
value_type
|
void
| ||||
difference_type
|
| ||||
pointer
|
void
| ||||
reference
|
void
| ||||
char_type
|
CharT
| ||||
traits_type
|
Traits
| ||||
streambuf_type
|
std::basic_streambuf<CharT, Traits>
| ||||
ostream_type
|
std::basic_ostream<CharT, Traits>
|
|
要求通过从 |
(C++17 前) |
成员函数
构造新的 ostreambuf_iterator (公开成员函数) | |
(析构函数) (隐式声明) |
销毁 ostreambuf_iterator (公开成员函数) |
| 写字符到关联的输出序列 (公开成员函数) | |
| 无操作 (公开成员函数) | |
| 无操作 (公开成员函数) | |
| 测试是否输出失败 (公开成员函数) |
示例
运行此代码
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
int main()
{
std::string s = "This is an example\n";
std::copy(s.begin(), s.end(), std::ostreambuf_iterator<char>(std::cout));
}
输出:
This is an example
参阅
| 从 std::basic_streambuf 读取的输入迭代器 (类模板) | |
| 写入 std::basic_ostream 的输出迭代器 (类模板) |