博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++基础--STL基本通用函数操作集合
阅读量:5963 次
发布时间:2019-06-19

本文共 3342 字,大约阅读时间需要 11 分钟。

// TimerTest.cpp : Using STL functions//并集,交集,差集,根据bound获取特定子集#include "stdafx.h"#include 
#include
#include
#include
#include
#include
using namespace std;int _tmain(int argc, _TCHAR* argv[]){ const int N = 6; string s1[N] = { "hell","cc","acc","bb","dd","kk"}; string s2[N] = { "ohell","ucc","yacc","nbb","mdd","ckk"}; set
A(s1,s1+N); set
B(s2,s2+N); ostream_iterator
out(cout," "); cout<<"Set A:"; copy(A.begin(),A.end(),out); cout<
C; cout<<"Set C:\n"; set_union(A.begin(),A.end(),B.begin(),B.end(),insert_iterator
>(C,C.begin())); copy(C.begin(),C.end(),out); string s3("grungy"); C.insert(s3); cout<<"Set C after insert s3:\n"; copy(C.begin(),C.end(),out); cout<
// TimerTest.cpp : Using STL functions //#include "stdafx.h"#include 
#include
#include
#include
using namespace std;typedef int KeyType;typedef pair
Pair;typedef multimap
MapCode;/**程序入口简单 multimap 应用。*/int _tmain(int argc, _TCHAR* argv[]){ MapCode codes; codes.insert(Pair(415,"San Francison")); codes.insert(Pair(510,"kingdom_0")); codes.insert(Pair(521,"lynn")); codes.insert(Pair(521,"forever love.")); codes.insert(Pair(415,"hehe.")); cout<<"Number of cities with the area code 415:" <
<
first<<"Value:"<
second<
range=codes.equal_range(521); cout<<"Cities with area code 521:\n"; for(it = range.first; it != range.second; it++) cout<<(*it).second<
 

 

// TimerTest.cpp : Using STL functions // 函数符#include "stdafx.h"#include 
#include
#include
#include
#include
using namespace std;template
//functor class defines operator()class TooBig{private: T cutoff;public: TooBig(const T &t):cutoff(t){} bool operator()(const T &v){ return v>cutoff;}};/**程序入口*/int _tmain(int argc, _TCHAR* argv[]){ TooBig
f100(100);//limit = 100 list
yedayada; list
etcetera; int vals[10] = { 50, 100, 90, 180, 60, 210, 415, 88, 188, 201}; yedayada.insert(yedayada.begin(),vals,vals+10); etcetera.insert(etcetera.begin(),vals,vals+10); ostream_iterator
out(cout," "); cout<<"Original lists:\n"; copy(yedayada.begin(),yedayada.end(),out); cout<
(200)); copy(etcetera.begin(),etcetera.end(),out); cout<
// TimerTest.cpp : Using STL functions //   transform demo#include "stdafx.h"#include 
#include
#include
#include
#include
#include
using namespace std;/**程序入口*/void Show(double);const int LIM = 5;int _tmain(int argc, _TCHAR* argv[]){ double arr1[LIM] = { 36, 39, 42, 45, 48}; double arr2[LIM] = { 25, 27, 29, 31, 33}; vector
gr8(arr1,arr1+LIM); vector
m8(arr2,arr2+LIM); cout.setf(ios_base::fixed); cout.precision(1); cout<<"gr8: \t"; for_each(gr8.begin(),gr8.end(),Show); cout<
sum(LIM); transform(gr8.begin(),gr8.end(),m8.begin(),sum.begin(),plus
()); cout<<"sum: \t"; for_each(sum.begin(),sum.end(),Show); cout<
prod(LIM); transform(gr8.begin(),gr8.end(),prod.begin(),bind1st(multiplies
(),2.5)); cout<<"prod: \t"; for_each(prod.begin(),prod.end(),Show); cout<

 

 

转载于:https://www.cnblogs.com/kingdom_0/articles/2565545.html

你可能感兴趣的文章
ASP.NET MVC 入门8、ModelState与数据验证
查看>>
linux进程调度之 FIFO 和 RR 调度策略---SYSTEMTAP
查看>>
JSTL的相关使用
查看>>
ActiveMQ, RabbitMQ和ZeroMQ 选型关注点
查看>>
王垠:完全用Linux工作
查看>>
Understanding the Router
查看>>
红米3 Flyme5.1.9.5插桩适配长期不定时更新
查看>>
MySQL 5.6 for Windows 解压缩版配置安装(转)
查看>>
组件居中显示 安卓
查看>>
delete
查看>>
sql server生成不重复的时间字符串
查看>>
DataBase 之 数据库设计六大范式
查看>>
比特币钱包安全
查看>>
Lucene就是这么简单
查看>>
2015年第6届蓝桥杯Java B组省赛试题解析
查看>>
一个有味道的函数
查看>>
zookeeper在linux环境安装
查看>>
Python_异常和模块
查看>>
【386天】跃迁之路——程序员高效学习方法论探索系列(实验阶段143-2018.02.26)...
查看>>
Java数据类型分类
查看>>