如何在unordered_map中插入 3 个元素或其他奇数个元素
How to insert 3 elements or another odd number of elements in an unordered_map?
我正在开发某种交通应用程序,我有车站,我把它们之间的连接放在一个unordered_map里。连接是:departure_station_id,arrival_station_id,travel_time。
如您所见,有三个元素。这是我已经尝试过的。
uint64_t fr=strtoul(from.c_str(),NULL,10);
uint64_t t=strtoul(to.c_str(),NULL,10);
uint64_t tf_time=strtoul(tfr.c_str(),NULL,10);
connections_hashmap.insert({{fr,t},tf_time});
我得到这个:
error: no matching function for call to ‘std::unordered_map<long unsigned int, std::unordered_map<long unsigned int, long unsigned int> >::insert(<brace-enclosed initializer list>)’ connections_hashmap.insert({{fr,t},tf_time});
我也尝试形成一个 {tf_time,NULL} 对,但我没有工作。
您应该将连接定义为结构,然后将其插入到某个有意义的 ID 下:
struct connection {
string departure_station_id;
string arrival_station_id;
string travel_time;
};
auto connections_hashmap = new unordered_map<string, connection>();
connections_hashmap.insert("connectionID", {"Powell", "Embarcadero", "3"});
这将允许您稍后通过连接 ID 检索结构。
相关文章:
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 为什么这个选择排序算法仍然切换一个元素,当它已经是其他元素中最小的元素时?
- 将 Vector<String > 元素复制到其他 Vector<String>* (1 作为
- 将向量C++中的每个其他元素累加
- 如果类包含基类类型的成员作为第一个元素,后跟其他成员,编译器是否可以优化空基?
- 我有一系列阵列.可以从一个数组中阅读一些元素和另一个数组中的其他元素
- 在一个类中向向量添加元素不适用于其他类
- 当从其他方法返回 vector 时,C++无法访问矢量元素
- 我无法将二维数组的两个元素的差异分配给C++中其他数组的元素?
- 将多种数据类型写入文件时的其他行和额外的数组元素
- 如何在unordered_map中插入 3 个元素或其他奇数个元素
- 检查unordered_set是否包含其他unordered_set中的所有元素 - C++
- C++11 在列表到映射(或其他容器)之间移动元素
- C++:从动态结构数组中删除元素并移动其他元素
- 为什么 size() 在与其他堆栈交换元素后提供错误的堆栈大小?
- 使用对其他枚举值的操作定义枚举元素值
- C 链接列表仅输出其他每个元素
- 从两个列之一返回值,或跳过数组中的所有其他元素
- 检查两个数组中的相似元素,为某些测试返回正确的值,为其他测试返回不正确的值
- 子级访问同一父级的其他子级的元素