在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是以键值对存放数据的