想问一下c++中的map的作用是什么?看到了map - 爱问答

(爱问答)

想问一下c++中的map的作用是什么?看到了map

网上都是一些简要的介绍,没有说map<char*是什么意思,我对c++不太了解,只是想知道这这个的用法

C++的map是一种数据结构

它可以存储二维的数组(你可以认为,它可以存储一张表)

且它数组的成员类型可以自定义的

如以下人员的年龄表:

姓名   年龄      

张三   22      

李四   20      

王五   23      

就可以用map实现

#include <string>
#include <map>
#include <iostream>
using namespace std;
typedef map<string, int, less<string> > info_type;

template <class First, class Second>
ostream& operator<<(ostream& out,
                   const pair<First,Second> & p)
{
cout << p.first << " 的年龄为 " << p.second << " 岁";
return out;
}

int main(void)
{

info_type info;
typedef info_type::value_type value_type;

info.insert(value_type(string("张三"),   22));
info.insert(value_type(string("李四"),   20));
info.insert(value_type(string("王五"),   23));

info_type::iterator p = info.begin();
while (p != info.end())
 cout  << *p++ << endl;

return 0;
}


下一篇:java属性封装的问题

上一篇:我1050的显卡为什么带不动吃鸡

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?