如何从地图的末尾开始
How to start at end of map
我希望能够从std::map
的末尾开始,以便首先检查列表末尾的项目,例如。。。
std::map<int> MapBasicExample;
MapBasicExample.insert(1);
MapBasicExample.insert(2);
MapBasicExample.insert(3);
MapBasicExample.insert(4);
MapBasicExample.insert(5);
当我使用MapBasicExample.begin()
时,首先检查的是值"5",并且我希望首先从循环中的1-5开始,而不是像使用MapBasicExample.begin()
时那样从5-1开始,如何做到这一点?
您可以按以下相反顺序迭代映射:
for (auto it = MapBasicExample.rbegin(); it != MapBasicExample.rend(); it++) {
std::cout << it->first << " = " << it->second << std::endl;
}
请记住,贴图有关键点和值。你的例子看起来像一套。不过,以相反的顺序对它们进行迭代的逻辑是相似的。
相关文章:
- 当回溯以零开始时,如何调试崩溃
- 为什么不;名字在地图上是按顺序排列的吗
- 基于多个条件处理地图中的所有元素
- 在C++中将矢量转换为嵌套地图
- 根据用户输入用字母填充矢量,并将"开始"和"结束"放在四肢
- 替换基于地图的所有引用
- 如何区分地图中的 0 和 false?
- 地图计数确实很重要,或者只是检查是否存在
- 如何从头开始创建 avi 文件?
- 为什么 -mmacosx-version-min=10.10 不阻止使用标记为从 10.11 开始的函数?
- 自一周开始以来的秒数?
- 如何从地图中删除矢量对象
- 是否有任何C++功能可以对地图进行排序?
- 如何使用 std::variant 打印地图键/值?
- 一旦双簧管录制开始,主 UI 线程就会被阻止
- 从矢量或地图中删除共享指针
- 在 c++ 中,有一种方法可以创建一个包含地图作为值的树状地图?
- 从特定键开始遍历地图
- 如何从特定位置开始搜索地图/多映像
- 如何从地图的末尾开始