STL——pair

功能:pair将一对值组合成一个值,这一对值可以具有不同的数据类型(T1和T2),两个值可以分别用pair的两个公有函数first和second访问。

#include <bits/stdc++.h>
using namespace std;
int main()
{

    pair< int,double > p1;
    pair< int,pair< int, int> > p2;
    pair< string,int > p3;
    
    p2.first = 1;
    p2.second.first=2;
    p2.second.second=3;
    cout<<p2.first<<" "<<p2.second.first<<" "<<p2.second.second<<endl;
    
    p3 = make_pair("abc",6);
    cout<<p3.first<<" "<<p3.second<<endl;
    
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/tonyyy/p/10351941.html