C++pair pair creation

C++pair pair creation

Function description:

For data that appears in pairs, two data can be returned by using pairs. There are two
ways to create:

pair<type, type>p(value1, value2);
pair<type, type>p = make_pair(value1, value2);

Code example:

#include<iostream>
#include<string>
using namespace std;
//pair对组的创建
void test01()
{
    
    
       //第一种方式
       pair<string, int>p("Tom", 20);
       cout << "姓名:" << p.first
              << " 年龄:"<<p.second << endl;
       //第二种方式
       pair<string, int>p2 = make_pair("Jerry", 30);
       cout << "姓名:" << p2.first
              << " 年龄:" << p2.second << endl;
}
int main()
{
    
    
       test01();
       system("pause");
       return 0;
}

Summary:
Both ways can create a pair, just remember one

Guess you like

Origin blog.csdn.net/gyqailxj/article/details/114627166