std::ostreambuf_iterator
| 定义于头文件 <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 是一个单趟 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
(公开成员函数) |
|
|
(destructor)
(implicitly declared)
|
销毁
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
写入的输出迭代器
(类模板) |