map基本概念
map构造和赋值
功能描述:
对map容器进行构造和赋值操作
函数原型:
代码如下:
#include <iostream>
using namespace std;
//map容器 构造和赋值
#include <map>void printMap(map<int, int> &m) {for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) {cout << "key = " << (*it).first << " " << "value = " << it->second << endl;}cout << endl;
}void test01() {//创建map容器map<int, int> m;m.insert(pair<int, int>(1, 10));m.insert(pair<int, int>(3, 30));m.insert(pair<int, int>(2, 20));m.insert(pair<int, int>(4, 40));printMap(m);//拷贝构造map<int, int >m2(m);printMap(m2);//赋值map<int, int>m3;m3 = m2;printMap(m3);}int main() {test01();return 0;
}