// 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
// 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<
// 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<