一 简介
1 头文件为<utility>
2 申明
template <class T1, class T2> struct pair;
二 pair定义及初始化的两种方式
1 模板实例化
std::pair<int, double> point1;
point1.first = 1;
point1.second = 2.2;
2 使用std::make_pair函数
auto point = std::make_pair(1, 2.2);
三 pair元素访问的两种方式
1 通过first和second访问
cout << "point.first: " << point.first << std::endl;
cout << "point.second: " << point.second << std::endl;
2 通过std::get函数访问
cout << "std::get<0>(point): " << std::get<0>(point) << std::endl;
cout << "std::get<1>(point): " << std::get<1>(point) << std::endl;
四 参考