头文件:
#include <vector>
特点:
pair默认对first升序,当first相同时对second升序。
类模板:
template<class T1,class T2>struct pair
参数:
T1:第一个参数的数据类型;
T2:第二个参数的数据类型。
功能:
pair将一对值组合成一个值,这一对值可以具有不同的数据类型(T1,T2);
两个值可以分别用共用函数first和second访问。
具体用法:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//根据first的值进行升序排序
bool cmp_first_up(pair<int,double> a, pair<int,double> b)
{
return a.first < b.first;
}
//根据second的值进行升序排序
bool cmp_second_up(pair<int,double> a,pair<int,double> b)
{
return a.second < b.second;
}
int main(int argc, char** argv) {
//1.定义
pair <int,double> p1;//使用默认