std::ostreambuf_iterator
| 迭代器概念 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 迭代器原语 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 算法概念与工具 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 间接可调用概念 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 常用算法要求 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 工具 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 迭代器适配器 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 流迭代器 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 迭代器定制点 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++20)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++20)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 迭代器操作 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 范围访问 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
在标头
<iterator>
定义
|
||
|
template< class CharT, class Traits = std::char_traits<CharT> >
class ostreambuf_iterator : public std::iterator<std::output_iterator_tag, |
(C++17 前) | |
|
template< class CharT, class Traits = std::char_traits<CharT> >
class ostreambuf_iterator; |
(C++17 起) | |
std::ostreambuf_iterator 是单趟老式输出迭代器 (LegacyOutputIterator)
,写入相继元素到为之创建迭代器的 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> |
|
要求通过从 std::iterator<std::output_iterator_tag, void, void, void, void> 继承获得成员类型
|
(C++17 前) |
成员函数
构造新的 ostreambuf_iterator (公开成员函数) |
|
|
(析构函数)
(隐式声明)
|
销毁 ostreambuf_iterator (公开成员函数) |
| 写字符到关联的输出序列 (公开成员函数) |
|
| 无操作 (公开成员函数) |
|
| 无操作 (公开成员函数) |
|
| 测试是否输出失败 (公开成员函数) |
示例
#include <string> #include <algorithm> #include <iterator> #include <iostream> 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 的输出迭代器 (类模板) |