std::ostreambuf_iterator
来自 cppreference.cn
< cpp | 迭代器 (iterator)
定义于头文件 <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
|
特性
| ||||
streambuf_type
|
std::basic_streambuf<CharT, Traits> | ||||
ostream_type
|
std::basic_ostream<CharT, Traits> |
成员类型 |
(C++17 前) |
[编辑] 成员函数
构造一个新的 ostreambuf_iterator (public member function) | |
(析构函数) (隐式声明) |
销毁一个 ostreambuf_iterator (public member function) |
向关联的输出序列写入一个字符 (public member function) | |
无操作 (public member function) | |
无操作 (public member function) | |
测试输出是否失败 (public member function) |
[编辑] 示例
运行此代码
#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读取的输入迭代器 (class template) | |
写入std::basic_ostream的输出迭代器 (class template) |