如何在 C++ 中反向迭代地图?
本文介绍了如何在 C++ 中反向迭代地图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I'm having trouble iterating in reverse over a map in GCC C++. When I use a reverse iterator, it seems I can't assign anything to it - the compiler complains. I'm working around it with some awkward code using a forward iterator, but it's not very elegant. Any thoughts?
解决方案
Here's an example of iterating backward through a std::map
:
If you are pre-C++11, you'll just need to spell out auto
, which is:
Note that if you're using boost, you can use a range-based for loop with a reverse adapter:
这篇关于如何在 C++ 中反向迭代地图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!