std::ostreambuf_iterator
来自 cppreference.cn
定义于头文件 <iterator> |
||
template< class CharT, class Traits = std::char_traits<CharT> > class ostreambuf_iterator |
(直到 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> |
成员类型 |
(直到 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 的输出迭代器 (类模板) |