c++ - 为什么 map 的键不能通过迭代器插入到向量中?
问题描述
我想获取地图的键,保存在向量中,所以我编写了以下代码:
#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 是从哪里出来的?
解决方案
推荐阅读
- c# - Twilio 使用 ngrok 测试出站呼叫
- c# - 尝试将列表项写入文本文件,但文件最终为空白
- powershell - 如何避免来自 [System.Net.Dns]::GetHostAddresses("$server_name") 的不必要输出
- python-3.x - 为什么 python turtle 不能正常工作,它导入,它绘制,但是它崩溃并且不能做任何事情:(
- email - 发送给邮件收件人 vbscript 不再工作
- java - 使用文档 doc = new Document(); 在卢森?
- python-3.x - 使用 matplotlib 排除 for 循环创建的图例中的图
- java - 2048变更检查方法java
- android - 在 Android 上读取系统文件时权限被拒绝
- javascript - 如何使用正则表达式删除空格、特殊字符和前导数字?