Когда я запускаю свой код, я получаю сообщение об ошибке:
Код: Выделить всё
terminate called after throwing an instance of 'std::out_of_range'
what(): _Map_base::at
Код ниже:
graph.h
Код: Выделить всё
#include
#include
#include
using namespace std;
//creates a struct for cities with name and isInternational variables
struct City {
string name; //name stored in variable of type string
bool isInternational; //boolean variable for if city is international or not
};
//creates graph class with function prototypes
class Graph {
public:
//function prototypes for adding cities, adding flights, and determining flight possibility
void addCity(const string& name, bool isInternational);
void addFlight(const string& from, const string& to);
bool canReach(const string& from, const string& to);
//function prototypes for retrieving cities & destinations
vector getCities() const;
vector getDestinations(const string& from) const;
private:
//uses unordered map to create lists for both cities & flights
unordered_map cities;
unordered_map flights;
};
Код: Выделить всё
//function definition for getDestinations function
vector Graph::getDestinations(const string& from) const {
vector result;
for (const auto& destination : flights.at(from)) {
result.push_back(cities.at(destination));
}
return result;
}
Источник: https://stackoverflow.com/questions/760 ... e-what-map