Hi
My current problem stmt is :- There are n no. of cities each having unique name and each city having m no. of streets. I have all the information as in which street belong to which city and so on. I'm able to extract information from the given input file using the function GetName now i want to store this information in some data structure. My current implementation goes like

....
string CityName;
string StreetName;
GetName(CityName,StreetName);
typedef vector<string> StrName;
map<string,StrName>cityMap;
map<string,StreetName>::iterator iterMap;
iterMap=cityMap.find(CityName);
if(iterMap==cityMap.end())
  {
   cityMap.insert((std::make_pair(CityName,StrName.push_back(StreetName)));
  }
else
     {
       //I want to insert value to the corresponding cityname or the returned iterator
     }

I'm getting compilation error while i'm trying to insert the value. Also once the values are inserted i need to retrieve them using simple for loop.How to do that in this case.
Kindly help

Recommended Answers

All 2 Replies

I m able to remove the compilation now.But still i have problem in inserting values for the cities whose name is already existing.

....
string CityName;
string StreetName;
GetName(CityName,StreetName);
typedef vector<string> StrName;
map<string,StrName>cityMap;
map<string,StreetName>::iterator iterMap;
iterMap=cityMap.find(CityName);
if(iterMap==cityMap.end())
{
 StrName.clear();
 StrName.push_back(StreetName);
 cityMap.insert((std::make_pair(CityName,StrName)));
}
else
{
 //I want to insert value to the corresponding cityname or the returned iterator
}

How to write code for the else part

....
string CityName;
string StreetName;
GetName(CityName,StreetName);
typedef vector<string> StrName;
map<string,StrName>cityMap;
map<string,StreetName>::iterator iterMap;
cityMap[ CityName ].push_back( StreetName ) ;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.