it->second{(*it).second}的作用,表示键值对中的数值部分,而it->first{(*it).first}表示键值部分

在API中:
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::map,它实际上存储的是一大堆std::对。这就是映射的真正含义——它将键和相关值配对在一起。
当您遍历std::map时,您是遍历所有这些std::对。当您取消对其中一个迭代器的引用时,您将得到一个包含键及其关联值的std::对。
现在std::pair类型允许您通过两个成员访问它的元素:first和second。所以如果你有一对std::配对,叫做p, p。首先是一个X对象和p。其次是一个Y对象。现在您知道了如何取消std::map迭代器的引用

关键的如下:

 (*it).first will give you the key 
 and (*it).second will give you the value. 
 it->first为键值;
 it->second为数值;
 例如map是以键值对存放数据的
  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值