STL容器pair对组

时间:2021-08-29 23:09:38   收藏:0   阅读:27

1.

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
using namespace std;
//创建对组
void test01()
{
    //第一种
    pair<string, int> p(string("Tom"), 100);
    //取值
    cout << "姓名: " << p.first << " 年龄:" << p.second << endl;

    //第二种
    pair<string, int> p2 = make_pair("Jerry", 20);
    cout << "姓名: " << p2.first << " 年龄:" << p2.second << endl;
}

int main()
{
    test01();
    system("Pause");
    return 0;
}

结果:

技术分享图片

 

原文:https://www.cnblogs.com/yifengs/p/15193809.html

评论(0)
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!