类模板:template <class T1, class T2> struct pair
参数:T1是第一个值的数据类型,T2是第二个值的数据类型。
功能:pair将一对值组合成一个值,这一对值可以具有不同的数据类型(T1和T2),两个值可以分别用pair的两个公有函数first和second访问。
#include <iostream>
#include <string>
using namespace std;
int main()
{
pair<char,int> p1;
pair<string,int> p2;
p1.first='c';
p1.second=100;
p2=make_pair("age",12);
cout<<p1.first<<"=>"<<p1.second<<endl;
cout<<p2.first<<"=>"<<p2.second<<endl;
return 0;
}