Problem in inserting values in map containing vector of string

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2007
Posts: 49
Reputation: tonyaim83 is an unknown quantity at this point 
Solved Threads: 0
tonyaim83 tonyaim83 is offline Offline
Light Poster

Problem in inserting values in map containing vector of string

 
0
  #1
Jan 31st, 2008
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

[Code language=c++]
....
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
}


[/Code]

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
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 49
Reputation: tonyaim83 is an unknown quantity at this point 
Solved Threads: 0
tonyaim83 tonyaim83 is offline Offline
Light Poster

Re: Problem in inserting values in map containing vector of string

 
0
  #2
Jan 31st, 2008
I m able to remove the compilation now.But still i have problem in inserting values for the cities whose name is already existing.
  1. ....
  2. string CityName;
  3. string StreetName;
  4. GetName(CityName,StreetName);
  5. typedef vector<string> StrName;
  6. map<string,StrName>cityMap;
  7. map<string,StreetName>::iterator iterMap;
  8. iterMap=cityMap.find(CityName);
  9. if(iterMap==cityMap.end())
  10. {
  11. StrName.clear();
  12. StrName.push_back(StreetName);
  13. cityMap.insert((std::make_pair(CityName,StrName)));
  14. }
  15. else
  16. {
  17. //I want to insert value to the corresponding cityname or the returned iterator
  18. }

How to write code for the else part
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: Problem in inserting values in map containing vector of string

 
0
  #3
Jan 31st, 2008
  1. ....
  2. string CityName;
  3. string StreetName;
  4. GetName(CityName,StreetName);
  5. typedef vector<string> StrName;
  6. map<string,StrName>cityMap;
  7. map<string,StreetName>::iterator iterMap;
  8. cityMap[ CityName ].push_back( StreetName ) ;
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2168 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC