#include<iostream>
#include<cstdlib>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
//typedef
typedef int I;
typedef char C;
typedef int ARR[10];
//宏定义
#define N 3
#define X(a,b) (((a)+(b))*3)
//自定义函数声明
void f1();
void output(const string &);
void f2();
//主函数
int main(int argc,char * argv[])
{
f1();
cout<<endl;
f2();
cout<<endl;
cout<<argc<<ends<<* argv<<endl;
system("pause");
return 0;
}
//自定义函数 在output函数里不能改变x的值,因为const
void output(const string & x)
{
cout<<x<<endl;
}
void f1()
{
//定义vector对象
vector<string> strVect1;
vector<string> strVect2;
//push_back()
strVect1.push_back("Sunday");
strVect1.push_back("Monday");
strVect1.push_back("Over");
strVect1.push_back("Wednesday");
strVect2.push_back("Monday");
strVect2.push_back("Sunday");
strVect2.push_back("Over");
strVect2.push_back("Saturday");
//sort()
sort(strVect1.begin(),strVect1.end());
sort(strVect2.begin(),strVect2.end());
cout<<"Vect1:"<<endl;
//for_each()
for_each(strVect1.begin(),strVect1.end(),output);
cout<<endl;
cout<<"Vect2:"<<endl;
for_each(strVect2.begin(),strVect2.end(),output);
cout<<endl;
cout<<"bool result=includes(strVect1.begin(),strVect1.end(),strVect2.begin(),strVect2.begin()+2):"<<endl;
//includes()
bool result=includes(strVect1.begin(),strVect1.end(),strVect2.begin(),strVect2.begin()+2);
if(result)
cout<<"result:OK"<<endl;
else
cout<<"result:ERROR"<<endl;
}
void f2()
{
//定义vector对象
vector<I> intVect;
//push_back()
intVect.push_back(7);
intVect.push_back(3);
intVect.push_back(9);
intVect.push_back(1);
intVect.push_back(0);
intVect.push_back(6);
intVect.push_back(5);
cout<<"intVect"<<endl;
//定义iterator对象
vector<I>::iterator it;
for(it=intVect.begin();it!=intVect.end();it++)
cout<<* it<<ends;
cout<<endl;
//nth_element()
nth_element(intVect.begin(),intVect.begin()+3,intVect.end());
for(it=intVect.begin();it!=intVect.end();it++)
cout<<* it<<ends;
cout<<endl;
}
精慕HU
相关分类