How can I traverse/iterate an STL map?

前端 未结 6 583
栀梦
栀梦 2021-01-30 02:14

I want to traverse an STL map. I don\'t want to use its key. I don\'t care about the ordering, I just look for a way to access all elements it contains. How can I do this?

6条回答
  •  轮回少年
    2021-01-30 03:01

    You can traverse STL map in the same way as any other STL container: using iterators, e.g.

    for (std::map::const_iterator
         i = myMap.begin(), end = myMap.end(); i != end; ++i)
    {
        // *i is a key-value pair
    }
    

提交回复
热议问题