• 迭代器


     1 #include "stdafx.h"
     2 #include<iostream>
     3 #include<iterator>
     4 #include<list>
     5 
     6 
     7 using namespace std;
     8 
     9     int iArray[5] = { 1, 2, 3, 4, 5 };
    10     void Display(list<int>&v, const char*s);
    11     int main()
    12     {
    13         list<int> iList;                                                    //定义了一个列表容器iList
    14         copy(iArray, iArray + 5, front_inserter(iList));                    //拷贝数组iArray到链表对象
    15         Display(iList, "Before find and copy");                     
    16         list<int>::iterator p = find(iList.begin(), iList.end(), 3);        //将适配器指向列表中的第三个数
    17         copy(iArray, iArray + 2, inserter(iList, p));                       
    18         Display(iList, "After find and copy");
    19         return 0;
    20     }
    21 
    22     void Display(list<int>&a, const char*s)
    23     {
    24         cout << s << endl;
    25         copy(a.begin(), a.end(), ostream_iterator<int>(cout, " "));         //输出迭代器使用空格符作为元素的分隔符
    26         cout << endl;
    27     }

    再比如说  ostream_iterator<int> output(cout," ");           //定义了一个output的输出迭代器

                 copy(vec.begin(),vec.end(),output);                   //以output的输出方式输出vector中的元素

  • 相关阅读:
    关于接口与抽象类
    C# 高级编程(笔记4)
    泛型与委托
    C# 高级编程(笔记2)
    构造函数的代码膨胀问题
    C# 高级编程(笔记3)
    C# 高级编程(笔记1)
    Web(7)补充
    理解synchronized对象锁
    robbin谈管理:改造团队的经验
  • 原文地址:https://www.cnblogs.com/zyb993963526/p/6024302.html
Copyright © 2020-2023  润新知