码迷,mamicode.com
首页 > 编程语言 > 详细

C++ Stream(串流)迭代器

时间:2019-12-30 21:40:16      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:system   color   cbe   copy   col   sys   div   begin   iterator   

C++ Stream(串流)迭代器

#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

int main()
{
    ostream_iterator<int> intWriter(cout,"\n");

    *intWriter = 42;
    intWriter++;

    *intWriter = 77;
    intWriter++;
    *intWriter = -5;

    vector<int> vector1 = {1,2,3,4,5,6,7,8,9};
    copy(vector1.cbegin(),vector1.cend(),ostream_iterator<int>(cout));
    cout << endl;

    copy(vector1.cbegin(),vector1.cend(),ostream_iterator<int>(cout,"  <  "));
    cout << endl;

    system("pause");
    return 0;
}

42
77
-5
123456789
1 < 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 <
请按任意键继续. . .

 

代码参考:C++标准库(第2版)

C++ Stream(串流)迭代器

标签:system   color   cbe   copy   col   sys   div   begin   iterator   

原文地址:https://www.cnblogs.com/herd/p/12121439.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!