I'm more used to a single map and not to nested map. So I have serious difficulty understanding how to deal with this.
Remark: Please don't request me to use multimap or boost,I'm restricted to use this structure
In C++ STL map, i have a definition like this
map<string, map<string, string>> exploration; // country --> state --> city
The first map represent a pair of key(country) and value as tree structure map<string, string>
which represent there respective state and city.
I know how to populate this structure manually (hard coding) like so:
exploration["Canada"]["Ontario"] = "Toronto";
Problem :
Later the data showed above will be entred by the user :
> Canada Ontario Toronto
> Canada Alberta Edmonton
> USA Washington Seatle
> USA Nevada Las-Vegas
So if I apply this logic to my example above, this is wrong since map does not accept duplicate keys
Illustration (wrong) :
exploration["Canada"]["Ontario"] = "Toronto";
exploration["Canada"]["Alberta"] = "Edmonton";
Illustration (What I'm looking for) :
exploration["Canada"]["Ontario"] = "Toronto";
["Alberta"] = "Edmonton";
Canada
**
* *
* *
Ontario Alberta
* *
* *
Toronto Edmonton
My hypothetical solution,
> Canada Ontario Toronto
1 case: If the country(Canada) does not exist in exploration structure,I add it as well as the province and its city.
2 case: If the country(Canada) exist, so I add Ontario and Toronto a long side the data entered before.
Any indications, ideas or hints are welcomed.