我正在研究某种过境应用程序,我有站点,我把它们之间的连接放在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"});
这将允许您稍后通过connectionID检索结构。