C ++迭代图

扫码查看
本文介绍了C ++迭代图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,以下代码用于在C ++中迭代map

As known the following code is used to iterate map in C++

for (std::map<char,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
{
    std::cout << itr->first << " => " << itr->second << '\n';
}

itr 声明为 std :: map :: iterator 的位置. std :: map std :: iterator .那怎么可以访问呢?

Where itr is declared as std::map::iterator. The members first and second are declared neither in std::map nor in std::iterator. Then how is it available for access?

推荐答案

std::mapstd::pair<key_type, mapped_type>,因此取消引用映射迭代器可为您提供对其中之一的引用.

The elements of an std::map are std::pair<key_type, mapped_type>, so de-referencing a map iterator gives you a reference to one of these.

这是 std::pair 类模板,该模板具有firstsecond成员.

这篇关于C ++迭代图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 03:45
查看更多