转自:https://blog.csdn.net/cbnotes/article/details/76594435
在构造map容器后,我们就可以往里面插入数据了。这里讲四种插入数据的方法:
第一种:用insert函数插入pair数据:在VC下请加入这条语句,屏蔽4786警告#pragmawarning(disable:4786))
map
mapStudent.insert(pair
mapStudent.insert(pair
mapStudent.insert(pair
第二种:用insert函数插入value_type数据,下面举例说明
map
mapStudent.insert(map
mapStudent.insert(map
mapStudent.insert(map
第三种:在insert函数中使用make_pair()函数,下面举例说明
map
mapStudent.insert(make_pair(1,“student_one”));
mapStudent.insert(make_pair(2,“student_two”));
mapStudent.insert(make_pair(3,“student_three”));
第四种:用数组方式插入数据,下面举例说明
map
mapStudent[1]=“student_one”;
mapStudent[2]=“student_two”;
mapStudent[3]=“student_three”;