为什么迭代器无法将地图的键插入向量中?

问题描述

我想获取地图的键,保存在矢量中,所以我编写了以下代码

#include <vector>
#include <iostream>
#include <map>

using namespace std;

int main() {
  map<int,int> m = {{1,2},{4,5},{6,7}};
  vector<int> a(m.begin()->first,m.end()->first);
  for (auto i : a) {
    cout << i << endl;   // output 3 here
  }
}

代码显示3,这使我感到困惑。 我从来没有在地图上输入3,哪里有3出来?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)