map::insert and map::find

来源:互联网 发布:mac系统如何压缩文件 编辑:程序博客网 时间:2024/05/12 13:03

定义一个map对象,其元素的键是家族姓氏,而值则是用pair类型的对象存储该家族孩子名字和年龄的vector对象,并且可以通过基于家族姓氏的查询输出该家族所有孩子的名字。

[注意]
[1] map对象的类型为 map< string, vector< pair<string, int> > >
[2] pair类型的头文件为utility
[3] map对象的insert操作,m.insert(value_type),其返回值为pair类型对象:pair<map<xxx,xxx>::iterator,bool>
[4] map对象的find操作,m.find(key),其返回值为指向该元素的迭代器:map<xxx,xxx>::const_iterator

类似的输出结果:


原创粉丝点击