编程语言
首页 > 编程语言> > C++ Stream(串流)迭代器

C++ Stream(串流)迭代器

作者:互联网

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版)

标签:cout,Stream,vector1,C++,intWriter,串流,iterator,include
来源: https://www.cnblogs.com/herd/p/12121439.html