首页 > 其他 > 详细

STL值map

时间:2021-01-21 12:16:57      阅读:27      评论:0      收藏:0      [点我收藏+]

1.map函数的概念与构造

技术分享图片

技术分享图片

#include<iostream>
using namespace std;
#include<map>

void printmap(map<int, int>p)
{
    for (map<int, int>::iterator it = p.begin(); it != p.end(); it++)
    {
        cout << "键值为:" << (*it).first << "实值:" << it->second << endl;
    }
}

int main(void)
{
    //map函数的插入,无论如何插入,map总会按照键值得顺序排列
    map<int, int>p;
    p.insert(pair<int, int>(3, 30));
    p.insert(pair<int, int>(2, 20));
    p.insert(pair<int, int>(6, 60));
    p.insert(pair<int, int>(1, 10));

    printmap(p);


    //map拷贝函数
    map<int, int>p2(p);
    printmap(p2);

    //map赋值
    map<int, int>p3;
    p3 = p2;
    printmap(p3);

    return 0;

}

 

STL值map

原文:https://www.cnblogs.com/loliconsk/p/14306246.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!