#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
------------------------------------------
请按任意键继续. . .

C++ fill fill_n generate generate_n的更多相关文章

  1. STL: fill,fill_n,generate,generate_n

    fill Assigns the same new value to every element in a specified range. template<class ForwardIter ...

  2. 填充整个区间(fill,fill_n,generate和generate_n)

    fill 将value值填充整个区间,不能为OutputIterator,因为fill会用到first和last,outputIterator无法做相等的测试 template <class F ...

  3. STL--STL和她的小伙伴们:

    STL--概述: 标准模板库(StandardTemplateLibrary,STL),是C++程序设计语言标准模板库.STL是由Alexander Stepanov.Meng Lee和David R ...

  4. STL六大组件之——算法小小小小的解析

    参考自侯捷的<stl源码剖析> stl算法主要分为非可变序列算法(指不直接修改其所操作的容器内容的算法),可变序列算法(指可以修改它们所操作的容器内容的算法),排序算法(包括对序列进行排序 ...

  5. 变易算法 - STL算法

    欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/mutating-algorithms.h ...

  6. STL常用遍历算法for_each和transform的比较

    for_each()和transform()算法比较 1)STL 算法 – 修改性算法  for_each()  copy()  copy_backward()  transform()  merge ...

  7. C++ STL 常用遍历算法

    C++ STL 常用遍历算法 STL的容器算法迭代器的设计理念 1) STL的容器通过类模板技术,实现数据类型和容器模型的分离 2) STL的迭代器技术实现了遍历容器的统一方法:也为STL的算法提供了 ...

  8. STL经常使用遍历算法for_each和transform的比較

    for_each()和transform()算法比較 1)STL 算法 – 改动性算法  for_each()  copy()  copy_backward()  transform()  merge ...

  9. cb41a_c++_STL_算法_填充新值fill_generate

    cb41a_c++_STL_算法_填充新值fill_generatefill(b,e,v)fill_n(b,n,v),填充n个vgenerate(b,e,p)generate_n(b,n,p) gen ...

随机推荐

  1. web开发原生开发混合开发的区别优势

    最近有人在讨论是原生开发好还是,混合开发好,以下是引用了数据来说: 最近原生应用.Web应用.混合应用的名字让我们听得比较熟悉了,现在我们就通过评析各种应用的优缺点来更进一步看看这三者的区别. 一.原 ...

  2. 使用pyinstaller打包使用scrapy模块的程序运行时出现No such file or directory的问题解决

    解决的方案是利用pyinstaller的hook特性,步骤如下: 1.在项目目录新建hooks目录,目录中新建hooks-scrapy.py 文件,文件内容如下: from PyInstaller.u ...

  3. 001_ARM学习_六大类指令集---LDR、LDRB、LDRH、LDM、STR、STRB、STRH、STM

    以下内容为转载: 注:非常感谢博主“希望之光”,文章转自他的博客:http://blog.chinaunix.net/uid-20379123-id-1956584.html   ARM的六大类指令集 ...

  4. 018_linux驱动之_阻塞和非阻塞

    阻塞操作     是指在执行设备操作时若不能获得资源则挂起进程,直到满足可操作的条件后再进行操作. 被挂起的进程进入休眠状态,被从调度器的运行队列移走,直到等待的条件被满足.   非阻塞操作   进程 ...

  5. Oracle 物理结构(三) 文件-参数文件

    一.参数文件介绍 Oracle中的参数文件是一个包含一系列参数以及参数对应值的操作系统文件.它们是在数据库实例启动时候加载的, 决定了数据库的物理 结构.内存.数据库的限制及系统大量的默认值.数据库的 ...

  6. xhEditor实现ctrl+v粘贴word图片并上传

    自动导入Word图片,或者粘贴Word内容时自动上传所有的图片,并且最终保留Word样式,这应该是Web编辑器里面最基本的一个需求功能了.一般情况下我们将Word内容粘贴到Web编辑器(富文本编辑器) ...

  7. bbs-admin-自定义admin(二)

    本文内容 目的:模仿admin默认配置,自定义配置类 一 查 1 查看数据 2 查看表头 3 分页器 4 search(搜索框)   5 action(批量处理)    6 filter(分类)   ...

  8. 【线性代数】7-2:线性变化的矩阵(The Matrix of a Linear Transformation)

    title: [线性代数]7-2:线性变化的矩阵(The Matrix of a Linear Transformation) categories: Mathematic Linear Algebr ...

  9. 1635:【例 5】Strange Way to Express Integers

    #include<bits/stdc++.h> #define ll long long using namespace std; ll n,m,a,lcm,now; bool flag; ...

  10. redis之redis-cluster配置

    为什么要用redis-cluster 并发问题 redis官方生成可以达到 10万/每秒,每秒执行10万条命令 假如业务需要每秒100万的命令执行呢? 数据量太大 一台服务器内存正常是16~256G, ...