pair操作指南

#include <iostream>
using namespace std;
#include <string>
#include <algorithm>
//成对出现的数据,利用对组可以返回两个数据
/*
两种创建方式
pair<type, type> p(value1, value2);
pair<type, type> p = make_pair(value1, value2);
*/
int main()
{
    pair<string, int> p("Tom", 20);
    cout << "姓名:" << p.first << " 年龄:" << p.second << endl;
    pair<string, int> p2 = make_pair("Candy", 23);
    cout << "姓名:" << p2.first << " 年龄:" << p2.second << endl;
    return 0;
}

 

posted @ 2021-08-27 13:06  花与不易  阅读(39)  评论(0)    收藏  举报