I need to find the fastest way from one city to other using djikstra algorithm (working on directed graph with weights), but i have to use this specific container. I have a problem with saving data properly to this map, here is part of my code.
fstream file;
string fromThisCity, toThisCity;
int distance;
file.open("drogi.txt", ios::in);
if (file.good())
{
while (!file.eof())
{
file >> fromThisCity;
file >> toThisCity;
file >> distance;
map<string, int> inGraph;
inGraph[toThisCity] = distance;
graph[fromThisCity] = inGraph;
for (map<string, map<string, int>>::iterator element = graph.begin(); element != graph.end(); element++)
{
for (map<string, int>::iterator i = inGraph.begin(); i != inGraph.end(); i++)
{
cout << element->first << " " << i -> first << " " << i -> second << endl;
}
}
}
}
else
{
cout << "file couldnt be opened" << endl;
}
file.close();