C++中->second 是什么意思
std::multimap<string,string>mtpphone;mtpphone.insert(std::make_pair("xiaozhu","123456...
std::multimap<string, string>mtpphone;
mtpphone.insert(std::make_pair("xiaozhu", "123456"));
mtpphone.insert(std::make_pair("xiaozhu", "1234567"));
std::multimap<string, string>::size_type count = mtpphone.count("xiaozhu");
std::multimap<string, string>::iterator it = mtpphone.find("xiaozhu");
for (std::multimap<string, string>::size_type i = 0; i != count;i++,it++)
{
cout << it->second<<endl;
}
second不知道是干什么的? 展开
mtpphone.insert(std::make_pair("xiaozhu", "123456"));
mtpphone.insert(std::make_pair("xiaozhu", "1234567"));
std::multimap<string, string>::size_type count = mtpphone.count("xiaozhu");
std::multimap<string, string>::iterator it = mtpphone.find("xiaozhu");
for (std::multimap<string, string>::size_type i = 0; i != count;i++,it++)
{
cout << it->second<<endl;
}
second不知道是干什么的? 展开
1个回答
追问
我其实 知道 我这个操作 是干什么用的 但我对于这个second 不太理解 他的作用是什么?
追答
if you have a std::map, what it actually stores is a whole bunch of std::pairs. That's exactly what a map is - it pairs together the keys and the associated values.
When you iterate over a std::map, you're iterating over all of these std::pairs. When you dereference one of these iterators, you get a std::pair containing the key and its associated value.
Now the type std::pair gives you access to its elements through two members: first and second. So if you have a std::pair called p, p.first is an X object and p.secondis a Y object.
So now you know that dereferencing a std::map iterator gives you a std::pair, you can then access its elements with first and second. For example, (*it).first will give you the key and (*it).second will give you the value. These are equivalent to it->first and it->second.
上面是我拷贝老外的解释,人家还是说的比较清楚的,迭代器的这两个方法就是为了获得std pair的key和keyvalue!百度字数不允许删了一点。'
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
富港检测技术(东莞)有限公司_
2024-08-05 广告
2024-08-05 广告
作为富港检测技术(东莞)有限公司的工作人员,关于ISTA 1A、2A及3A的区别及测试项目简述如下:ISTA 1A是非模拟集中性能试验,主要进行固定位移振动和冲击测试,针对不超过68kg的包装件。ISTA 2A则在此基础上增加了部分模拟性能...
点击进入详情页
本回答由富港检测技术(东莞)有限公司_提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询