zoukankan      html  css  js  c++  java
  • C++ STL copy copy_backward

    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <functional>
    #include <list>

    using namespace std;


    int main()
    {
      list<int> list1;
      for (int k=0;k<10;k++)
      {
        list1.insert(list1.end(),k);
      }

      list<int>::iterator list_iter1;
      for (list_iter1 = list1.begin();list_iter1 != list1.end();++list_iter1)
      {
        cout << *list_iter1 << " ";
      }
      cout << endl;
      cout << "----------------------------------------------------------" << endl;

      vector<int> vec1(list1.size()*2);
      vector<int>::iterator vec_iter1;

      for (vec_iter1 = vec1.begin();vec_iter1 != vec1.end(); ++vec_iter1)
      {
        cout << *vec_iter1 << " ";
      }
      cout << endl;
      cout << "----------------------------------------------------------" << endl;

      copy(list1.begin(),list1.end(),vec1.begin());
      for (vec_iter1 = vec1.begin(); vec_iter1 != vec1.end(); ++vec_iter1)
      {
        cout << *vec_iter1 << " ";
      }
      cout << endl;
      cout << "----------------------------------------------------------" << endl;

      copy_backward(list1.begin(),list1.end(),vec1.end());
      for (vec_iter1 = vec1.begin(); vec_iter1 != vec1.end(); ++vec_iter1)
      {
        cout << *vec_iter1 << " ";
      }
      cout << endl;
      cout << "----------------------------------------------------------" << endl;


      system("pause");
      return 0;
    }

    ========================================================

    0 1 2 3 4 5 6 7 8 9
    ----------------------------------------------------------
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    ----------------------------------------------------------
    0 1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 0 0 0
    ----------------------------------------------------------
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
    ----------------------------------------------------------
    请按任意键继续. . .

  • 相关阅读:
    零点起飞学Word与Excel高效办公实战与技巧
    C语言核心技术(原书第2版)
    完全精通Nuendo电脑音乐及音频制作:精细操作与实践指南
    1035.找出直系亲属(floyd)
    1033.继续XXX定律
    1034.寻找大富翁
    1032.ZOJ问题
    1029.魔咒词典
    1031.XXX定律
    1028.继续畅通工程
  • 原文地址:https://www.cnblogs.com/herd/p/11007450.html
Copyright © 2011-2022 走看看