社区
C++ 语言
帖子详情
有谁知道STL map的具体用法??
折腾_苏州
2005-10-21 07:37:17
有谁知道STL map的具体用法??给个例子,小弟正在学习,不太会用。谢谢了。。
...全文
203
5
打赏
收藏
有谁知道STL map的具体用法??
有谁知道STL map的具体用法??给个例子,小弟正在学习,不太会用。谢谢了。。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
syscoder
2005-10-23
打赏
举报
回复
http://www.stlchina.org/twiki/bin/view.pl/Main/STLDetailHashMap
jsjjms
2005-10-21
打赏
举报
回复
呵呵,学习!
fangrk
2005-10-21
打赏
举报
回复
struct ltstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};
int main()
{
map<const char*, int, ltstr> months;
months["january"] = 31;
months["february"] = 28;
months["march"] = 31;
months["april"] = 30;
months["may"] = 31;
months["june"] = 30;
months["july"] = 31;
months["august"] = 31;
months["september"] = 30;
months["october"] = 31;
months["november"] = 30;
months["december"] = 31;
cout << "june -> " << months["june"] << endl;
map<const char*, int, ltstr>::iterator cur = months.find("june");
map<const char*, int, ltstr>::iterator prev = cur;
map<const char*, int, ltstr>::iterator next = cur;
++next;
--prev;
cout << "Previous (in alphabetical order) is " << (*prev).first << endl;
cout << "Next (in alphabetical order) is " << (*next).first << endl;
}
fiftymetre
2005-10-21
打赏
举报
回复
学习这个你还是看看,C++标准程序库吧
fiftymetre
2005-10-21
打赏
举报
回复
Map是一类关联式容器。它的特点是增加和删除节点对迭代器的影响很小,除了那个操作节点,对其他的节点都没有什么影响。对于迭代器来说,可以修改实值,而不能修改key。
Map的每一个结点都是一个pair,insert的元素也是pair。主要注意的是key不能重复。算法建议采用Map自带的算法,而不用启用STL的通用算法,因为这个地方做了优化。
map<int,string> MapContaint;
MapContaint[1] = string("Map1");
MapContaint[2] = string("Map2");
pair<int,string> tmp(3,string("Map3"));
MapContaint.insert(tmp);
map<int,string>::iterator i = MapContaint.begin();
for (;i!=MapContaint.end();i++)
{
printf("%d\n",i->first);
}
map<int,string>::iterator ptr = MapContaint.begin();
ptr = MapContaint.find(2);
cout << ptr->second << endl;
STL
中
map
用法
详解
STL
中
map
用法
详解
STL
中
map
用法
详解
STL
中
map
用法
详解
STL
中
map
用法
详解
STL
中
map
用法
详解
stl
中
map
用法
详解
stl
中
map
用法
详解
STL
中
map
用法
详解
STL
中
map
用法
详解
STL
中
map
用法
详解
STL
中
map
用法
详解
STL
中
map
用法
详解
STL
中
map
用法
详解
如果你具备一定的C++ template知识,即使你没有接触过
STL
,这个文章你也应该可能较轻易的看懂。
STL
中
map
用法
详解.rar
STL
中
map
用法
详解
STL
中
map
用法
详解
STL
中
map
用法
详解
C++ 语言
64,648
社区成员
250,503
社区内容
发帖
与我相关
我的任务
C++ 语言
C++ 语言相关问题讨论,技术干货分享,前沿动态等
复制链接
扫一扫
分享
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
请不要发布与C++技术无关的贴子
请不要发布与技术无关的招聘、广告的帖子
请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下
试试用AI创作助手写篇文章吧
+ 用AI写文章