std::ostream_iterator<T,CharT,Traits>::ostream_iterator
< cpp | iterator | ostream iterator
ostream_iterator(ostream_type& stream, const CharT* delim) |
(1) | |
ostream_iterator(ostream_type& stream) |
(2) | |
1) 以
stream
为关联流并以 delim
为分隔符构造迭代器。2) 以
stream
为关联流并以空指针为分隔符构造迭代器。参数=
stream | - | 此迭代器所访问的输出流 |
delim | - | 在每次输出后插入流的空终止字符串 |
示例
运行此代码
#include <iostream> #include <iterator> #include <algorithm> int main() { std::ostream_iterator<int> i1(std::cout, ", "); std::fill_n(i1, 5, -1); std::ostream_iterator<double> i2(std::cout); *i2++ = 3.14; }
输出:
-1, -1, -1, -1, -1, 3.14