zoukankan      html  css  js  c++  java
  • 迭代器

     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中的元素

  • 相关阅读:
    Js定义一个表单并提交
    jQuery插件3种类型
    Jquery.extend()和jQuery.fn.extend(object);
    maven 依赖调解
    DOS 查看端口占用,Kill线程
    git 笔记
    mongodb添加登陆验证
    react 使用fortawesome字体图标
    redux小结
    MDM-Object.fn 一些实践与理解
  • 原文地址:https://www.cnblogs.com/zyb993963526/p/6024302.html
Copyright © 2011-2022 走看看