std::ostream_iterator<T,CharT,Traits>::ostream_iterator
来自cppreference.com
| |
(1) | |
| |
(2) | |
以 stream(通过存储地址)作为关联流并构造迭代器。
1) 以
delim 作为分隔符。2) 以空指针作为分隔符。
参数
| stream | - | 此迭代器所访问的输出流 |
| delim | - | 在每次输出后插入流的空终止字符串 |
示例
运行此代码
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
int main()
{
std::ostream_iterator<char> oo{std::cout};
std::ostream_iterator<int> i1{std::cout, ", "};
std::fill_n(i1, 5, -1);
*oo++ = '\n';
std::ostream_iterator<double> i2{std::cout, "; "};
*i2++ = 3.14;
*i2++ = 2.71;
*oo++ = '\n';
std::common_iterator<std::counted_iterator<std::ostream_iterator<float>>,
std::default_sentinel_t>
first{std::counted_iterator{std::ostream_iterator<float>{std::cout," ~ "}, 5}},
last{std::default_sentinel};
std::iota(first, last, 2.2);
*oo++ = '\n';
}
输出:
-1, -1, -1, -1, -1,
3.14; 2.71;
2.2 ~ 3.2 ~ 4.2 ~ 5.2 ~ 6.2 ~
缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
