copy:

 Copy函数原型:标头: <algorithm>

OutputIterator copy(

InputIterator begin,

InputIterator end,

outputIterator Result)

返回的结果为:OutputIterator容器的Result到Result+(end-begin)位置被InputIterator
容器begin到end位置的数据覆盖。[begin,end)

#include
<vector>

#include
<algorithm>

#include
<iostream>

using  namespace std;

void main()

{

vector<int> vec1,vec2;

for(int i=0;i<=5;++i)

{

vec1.push_back(i*2);

}

for(int i=0;i<=10;++i)

{

vec2.push_back(i*3);

}

cout<<"vec1 数据项依次为:";

for(vector<int>::iterator iter=vec1.begin();iter!=vec1.end();iter++)

{

cout<<*iter<<"   ";

}

cout<<endl<<"vec2的数据项依次为:";

for(vector<int>::iterator iter=vec2.begin();iter!=vec2.end();iter++)

{

cout<<*iter<<"   ";

}

//copy,更新vec2的数据,

copy(vec1.begin(),vec1.end(),vec2.begin());

cout<<endl<<"更新后的vec2:";

for(vector<int>::iterator iter=vec2.begin();iter!=vec2.end();iter++)

{

cout<<*iter<<"   ";

}

system("pause");

}

abs: 数据的绝对值

#include
<iostream>

#include
<valarray>

using namespace std;

const int  nums=10;

void main()

{

//集合应用

valarray<int> val_old(nums);

for(int i=0;i<nums;++i)

{

val_old[i]=-i;

}

cout<<"the size of val_old 
is :"<<val_old.size()<<endl;

cout<<"before abs list is: ";

for(int i=0;i<nums;++i)

{

cout<<val_old[i];

if(i<nums-1)

{

cout<<",";

}

}

valarray<int> val_new=abs(val_old);
//将整合集合对象传给方法,每个元素都变

cout<<endl<<"after abs:";

for(int i=0;i<nums;++i)

{

cout<<val_new[i];

if(i<nums-1)

{

cout<<",";

}

}

//单个对象。

double d=-9.909;

double abs_d=abs(d);

cout<<endl<<abs_d+d;

system("pause");

}

 

includes:标头: <algorithm>

函数原型:bool includes(

InputIterator1 First1,

InputIterator1 Last1,

InputIterator2 First2,

InputIterator2 Last2

)

集合序列与集合序列之间的包含与否!

#include
<iostream>

#include
<algorithm>

#include
<functional>

#include
<string>

#include
<deque>

using namespace std;

int main()

{

deque<string>::size_type nums=5;

deque<string> strs_big(nums);

deque<string> strs_small(3);

strs_big.push_back("one");

strs_big.push_back("two");

strs_big.push_back("three");

strs_big.push_back("four");

strs_big.push_back("");

strs_small.push_back("");

strs_small.push_back("two");

strs_small.push_back("four");

sort(strs_big.begin(),strs_big.end());

sort(strs_small.begin(),strs_small.end());

cout<<endl<<"较大串的数据元素有:";

for(deque<string>::iterator ite=strs_big.begin();ite!=strs_big.end();++ite)

{

cout<<*ite<<"  ";

}

cout<<endl<<"较小串的数据元素有:";

for(deque<string>::iterator it=strs_small.begin();it!=strs_small.end();++it)

{

cout<<*it<<"  ";

}

if(includes(strs_big.begin(),strs_big.end(),strs_small.begin(),strs_small.end()))

{

cout<<endl<<"大串包含小串!Y";

}

else

{

cout<<endl<<"大串不包含小串!N";

}

system("pause");

}

copy ,abs,includes 3个函数的更多相关文章

  1. abs()函数的返回值问题

    转载原文地址:http://www.cnblogs.com/webary/p/4967868.html 在牛客网看到一道关于abs()函数返回值的题目,见下图,当时还没反应过来,第一反应是:自从我开始 ...

  2. Python 函数参数引用(传值/传址)/copy/deepcopy

    精简版: 传值:被调函数局部变量改变不会影响主调函数局部变量 传址:被调函数局部变量改变会影响主调函数局部变量 Python参数传递方式:传递对象引用(传值和传址的混合方式),如果是数字,字符串,元组 ...

  3. 那个你经常用的abs函数(取绝对值)真的总是返回非负数吗?

    前几天在牛客网看到一道关于abs()函数返回值的题目,见下图,当时还没反应过来,第一反应是:自从我开始学C语言,就知道它是用来求int数的绝对值的,返回值当然是0或者正数啊,一看答案就是A. 后来思来 ...

  4. Delphi 数学函数:常用的几个数学函数(Power、Abs、Int、Trunc、Round、Frac、sqr、sqrt)

    Delphi 常用的几个数学函数 1 Power函数,求次方 定义:function Power(X,Y): (Same type as parameter); 说明:X可以是整型,也可以是实型:返回 ...

  5. Python高手之路【三】python基础之函数

    基本数据类型补充: set 是一个无序且不重复的元素集合 class set(object): """ set() -> new empty set object ...

  6. Delphi 使用之函数

    函数由一句或多句代码组成,可以实现某个特定的功能.使用函数可以使代码更加易读.易懂,加快编程速度及减少重复代码.过程与函数类似,过程与函数最重要的区别在于,过程没有返回值,而函数能有返回值.     ...

  7. Excel函数进阶

    #笔记:为了方便自己以后查找,以便随时随地能查看.形成系统化学习! 查找引用函数 ------------------包含----------Vlookup函数(if数组).Hlookup函数.loo ...

  8. 人生苦短之我用Python篇(遍历、函数、类)

    #遍历 info = {'key1':'value1','key2':'value2','key3':'value3'} #方式一 for i in info: print(i,info[i]) #方 ...

  9. python学习道路(day4note)(函数,形参实参位置参数匿名参数,匿名函数,高阶函数,镶嵌函数)

    1.函数 2种编程方法 关键词面向对象:华山派 --->> 类----->class面向过程:少林派 -->> 过程--->def 函数式编程:逍遥派 --> ...

随机推荐

  1. DOM操作-倒排序子元素

    代码: —————————————————————————————— <script type="text/javascript">                // ...

  2. JavaScript高级程序设计:第六章

    第六章 面向对象的程序设计 一.理解对象 1.属性类型: ECMAScript中有两种属性:数据属性和访问器属性. (1)数据属性: 数据属性包含一个数据值的位置.在这个位置可以读取和写入值.数据属性 ...

  3. java中static关键字解析

    static关键字是很多朋友在编写代码和阅读代码时碰到的比较难以理解的一个关键字,也是各大公司的面试官喜欢在面试时问到的知识点之一.下面就先讲述一下static关键字的用法和平常容易误解的地方,最后列 ...

  4. 解析好的静态页面.shtml浏览器无法解析.需要apache解析后再返回给浏览器

    解析好的静态页面.shtml浏览器无法解析.需要apache解析后再返回给浏览器 让Apache支持SHTML(SSI)的配置方法 http.conf放开addtype text/html .shtm ...

  5. how to add a shared lib in C?

    http://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html Basically, 2 steps: 1) make the ...

  6. 图解HTTP读书笔记--精简版

    这本书重点讲了两点,分别是 HTTP的报文格式 HTTPS比HTTP优秀在哪里 接下来分部分讨论一下: 1. HTTP的报文格式 请求报文格式: 请求行     指明请求方法 请求路径 和协议   如 ...

  7. cmd命令行查看当前系统版本和版本是32位还是64位

  8. lvs + keepalived + httpd 高可用集群(转)

    实验信息和拓扑:备注:Centos 6.5 selinux –disabled iptables off ServerName Ipaddress information LVSMaster 172. ...

  9. photoshop 魔术橡皮擦

    魔术棒和橡皮的结合,不用解锁就能抠图

  10. ASP.NET MVC3 系列教程 - 目录

    ASP.NET MVC3 系列教程 - 目录   I:ASP.NET MVC3 新增的功能 ASP.NET MVC3 系列教程 - Razor视图引擎基础语法ASP.NET MVC3 系列教程 - V ...