• C++ fill fill_n generate generate_n


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

    using namespace std;


    int main()
    {
      list<string> list1;
      list1.push_back("A");
      list1.push_back("B");
      list1.push_back("C");

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

      fill(list1.begin(), list1.end(), "D");
      for (list_iter1 = list1.begin(); list_iter1 != list1.end(); ++list_iter1)
      {
        cout << *list_iter1 << " ";
      }
      cout << endl;
      cout << "------------------------------------------" << endl;

      list<string> list2;
      for (int k=0;k<12;k++)
      {
        list2.push_back("E");
      }

      list<string>::iterator list_iter2;
      for (list_iter2 = list2.begin(); list_iter2 != list2.end(); ++list_iter2)
      {
        cout << *list_iter2 << " ";
      }
      cout << endl;
      cout << "------------------------------------------" << endl;


      fill_n(list2.begin(), 9, "F");
      for (list_iter2 = list2.begin(); list_iter2 != list2.end(); ++list_iter2)
      {
        cout << *list_iter2 << " ";
      }
      cout << endl;
      cout << "------------------------------------------" << endl;

      list<int> list3;
      generate_n(back_inserter(list3), 5, rand);

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

      generate(list3.begin(), list3.end(), rand);
      for (list_iter3 = list3.begin(); list_iter3 != list3.end(); ++list_iter3)
      {
        cout << *list_iter3 << " ";
      }
      cout << endl;
      cout << "------------------------------------------" << endl;

      system("pause");
      return 0;
    }

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

    A B C
    ------------------------------------------
    D D D
    ------------------------------------------
    E E E E E E E E E E E E
    ------------------------------------------
    F F F F F F F F F E E E
    ------------------------------------------
    41 18467 6334 26500 19169
    ------------------------------------------
    15724 11478 29358 26962 24464
    ------------------------------------------
    请按任意键继续. . .

  • 相关阅读:
    vb.net EXCEL进程问题
    VB.NET 中使用正则表达式
    改变鼠标状态
    举证信息表,语言不是VB.NET 是VBA的
    初学查询时的一些东西
    删除关联错误
    对于 using ESRI.ArcGIS.Carto; 的引用。是否缺少 using 指令或程序集引用
    AxMapControl 引用问题
    堆排序:大顶堆,小顶堆
    abs()函数,fabs函数(),max()函数的区别
  • 原文地址:https://www.cnblogs.com/herd/p/11010268.html
Copyright © 2020-2023  润新知