std::experimental::ostream_joiner
来自 cppreference.cn
< cpp | experimental
定义于头文件 <experimental/iterator> |
||
template< class DelimT, |
(library fundamentals TS v2) | |
std::experimental::ostream_joiner
是一个单程 LegacyOutputIterator,它将连续的对象写入为其构造的 std::basic_ostream 对象,使用 operator<<
,并用分隔符分隔。分隔符写在每两个写入对象的输出流之间。写入操作在迭代器(无论是否解引用)被赋值时执行。递增 ostream_joiner
是空操作。
在典型的实现中,ostream_joiner
的唯一数据成员是指向关联的 std::basic_ostream 的指针、分隔符和一个 bool 成员,该成员指示下一次写入是否是序列中的第一个元素。
与 std::ostream_iterator 相比,ostream_joiner
打印分隔符序列的次数少一次,并且没有以要打印的对象类型为模板。
目录 |
[编辑] 成员类型
成员类型 | 定义 |
char_type
|
CharT
|
traits_type
|
Traits
|
ostream_type
|
std::basic_ostream<CharT, Traits> |
value_type
|
void |
difference_type
|
void |
pointer
|
void |
reference
|
void |
iterator_category
|
std::output_iterator_tag |
[编辑] 成员函数
构造一个新的 ostream_joiner (public member function) | |
(析构函数) (隐式声明) |
析构一个 ostream_joiner (public member function) |
将对象写入关联的输出序列 (public member function) | |
空操作 (public member function) | |
空操作 (public member function) |
[编辑] 非成员函数
创建一个 ostream_joiner 对象,从函数参数中推导模板的类型参数(function template) |
[编辑] 示例
运行此代码
#include <algorithm> #include <experimental/iterator> #include <iostream> #include <iterator> int main() { int i[] = {1, 2, 3, 4, 5}; std::copy(std::begin(i), std::end(i), std::experimental::make_ostream_joiner(std::cout, ", ")); }
输出
1, 2, 3, 4, 5
[编辑] 参见
输出迭代器,写入到 std::basic_streambuf (class template) | |
输出迭代器,写入到 std::basic_ostream (class template) | |
输入迭代器,从 std::basic_istream 读取 (class template) |