| | |
Problem in inserting values in map containing vector of string
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2007
Posts: 49
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Aug 2007
Posts: 49
Reputation:
Solved Threads: 0
I m able to remove the compilation now.But still i have problem in inserting values for the cities whose name is already existing.
How to write code for the else part
c++ Syntax (Toggle Plain Text)
.... 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
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
c++ Syntax (Toggle Plain Text)
.... 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 ) ;
![]() |
Other Threads in the C++ Forum
- Previous Thread: Im done with My IPO CHART Tell me if Its Right
- Next Thread: Error2501: missing storage-class or type specifiers
Views: 2168 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






