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

using namespace std;

int main()
{
  list<int> list1;
  list<int> list2;

  for (int k=0;k<10;k++)
  {
    list1.push_back(k);
  }

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

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

  replace_if(list1.begin(), list1.end(), bind2nd(less<int>(), 5), 11);
  for (list_iter1 = list1.begin(); list_iter1 != list1.end(); ++list_iter1)
  {
    cout << *list_iter1 << " ";
  }
  cout << endl;
  cout << "-----------------------------------------------------" << endl;

  for (int k=0;k<7;k++)
  {
    list2.push_back(k);
  }

  for (int k = 4; k<10; k++)
  {
    list2.push_back(k);
  }

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

  replace_copy(list2.begin(), list2.end(), ostream_iterator<int>(cout, " "), 5, 55);
  cout << endl;
  cout << "-----------------------------------------------------" << endl;

  replace_copy_if(list2.begin(), list2.end(), ostream_iterator<int>(cout, " "), bind2nd(less<int>(), 5), 46);
  cout << endl;
  cout << "-----------------------------------------------------" << endl;

  system("pause");
  return 0;
}

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

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

C++ replace replace_if replace_copy replace_copy_if的更多相关文章

  1. 替换元素(replace,replace_if,replace_copy,replace_copy_if)

    replace 审阅range中的每个元素,把old_value替换为new_value template <class ForwardIterator,class T> void rep ...

  2. 算法 replace,replace_copy,back_inserter

    replace (list.begin(), list.end(), , ); // replace any elements with value of 0 by 42 replace算法对输入序列 ...

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

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

  4. STL函数模板(即算法)一览

    查找算法 adjacent_find:找出一个串中第一个不符合次序的地方 find,find_if:找出第一个符合条件的元素 find_first_of:在一个串中寻找第一个与另一个串中任意一个元素相 ...

  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. STL源代码剖析——STL算法stl_algo.h

    前言 在前面的博文中剖析了STL的数值算法.基本算法和set集合算法.本文剖析STL其它的算法,比如排序算法.合并算法.查找算法等等.在剖析的时候.会针对函数给出一些样例说明函数的使用.源代码出自SG ...

随机推荐

  1. Aop动态代理和cglib

    一般我们使用Aop对象时,常用动态代理模式,即是采用映射一个相同的类在此基础上进行前置后置操作. 动态代理多是采用原类实现父类接口,然后动态代理一个和原类相同的双胞胎兄弟类来实现映射. 父类 publ ...

  2. Computer Vision_33_SIFT:Object recognition from local scale-invariant features——1999

    此部分是计算机视觉部分,主要侧重在底层特征提取,视频分析,跟踪,目标检测和识别方面等方面.对于自己不太熟悉的领域比如摄像机标定和立体视觉,仅仅列出上google上引用次数比较多的文献.有一些刚刚出版的 ...

  3. 安装sass时遇到Failed to build gem native extension

    错误信息 执行命令: sudo gem install sass时遇到下面的错误信息 Building native extensions. This could take a while... ER ...

  4. linux 、 CentOs ---> 环境变量设置

    Linux下环境变量设置 1.在Windows 系统下,很多软件安装都需要配置环境变量,比如 安装 jdk ,如果不配置环境变量,在非软件安装的目录下运行javac 命令,将会报告找不到文件,类似的错 ...

  5. 【python】使用xlrd,xlwt来操作已存在的excel表

    import xlrd import xlwt from xlutils.copy import copy # 打开想要更改的excel文件 old_excel = xlrd.open_workboo ...

  6. vscode开发

    基于 Electron 开发.typescript编写.底层 Node.js 打造的一个编辑器 , 不是IDE,被称为“披着IDE外衣的编辑器”

  7. Spring MVC + freemarker实现半自动静态化

    这里对freemarker的代码进行了修改,效果:1,请求.do的URL时直接生成对应的.htm文件,并将请求转发到该htm文件2,自由控制某个页面是否需要静态化原理:对org.springframe ...

  8. [Google Guava] 9-I/O

    原文链接 译文链接 译者:沈义扬 字节流和字符流 Guava使用术语”流” 来表示可关闭的,并且在底层资源中有位置状态的I/O数据流.术语”字节流”指的是InputStream或OutputStrea ...

  9. Air Raid POJ - 1422 【有向无环图(DAG)的最小路径覆盖【最小不相交路径覆盖】 模板题】

    Consider a town where all the streets are one-way and each street leads from one intersection to ano ...

  10. request.getParameter乱码

    String str= new String(request.getParameter("xxxx").getBytes("ISO-8859-1")," ...