【发布时间】:2023-03-25 22:24:02
【问题描述】:
我正在开发某种交通应用程序,我有车站,我将它们之间的连接放在 unordered_map 中。一个连接是:department_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} 对,但我没有工作。
【问题讨论】:
-
地图与字典几乎相同。在字典中,你给它一个单词,它给你一个定义。同样,对于一张地图,你给它一个key,它给你一个value。因此,如果您要在这里使用地图,您必须确定合适的键是什么:您希望能够查找什么。您必须为该值提供单一类型,通常是
struct(或class),其中包含属于该值的各个部分。 -
请提供minimal reproducible example;至少,
connections_hashmap的定义。
标签: c++ c++11 unordered-map