473,785 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem in inserting values in map.

4 New Member
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

Expand|Select|Wrap|Line Numbers
  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.    cityMap.insert((std::make_pair(CityName,StrName.push_back(StreetName)));
  12.   }
  13. else
  14.      {
  15.        //I want to insert value to the corresponding cityname or the returned iterator
  16.      } 
  17.  
  18.  
  19.  
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
Jan 31 '08 #1
3 1486
DumRat
93 New Member
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

Expand|Select|Wrap|Line Numbers
  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.    cityMap.insert((std::make_pair(CityName,StrName.push_back(StreetName)));
  12.   }
  13. else
  14.      {
  15.        //I want to insert value to the corresponding cityname or the returned iterator
  16.      } 
  17.  
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
macho,
Do follow the naming conventions, it's a little hard to read your code at first.
What are the compilation errors?
Jan 31 '08 #2
tonyaim83
4 New Member
I m able to remove the compilation now.But still i have problem in inserting values for the cities whose name is already existing.
Expand|Select|Wrap|Line Numbers
  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. }
  19.  
  20.  
How to write code for the else part
Jan 31 '08 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
I think you have problem in your design.

If a city has a unique name and each city as a number of streets, then I would expect a container of cities where each city is a container of streets:
Expand|Select|Wrap|Line Numbers
  1. map<string, map<string> > MyMap;
  2.  
Here you acess MyMap using thge city name and the returned pair second member will be the map of the streets for that city.
Jan 31 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
2732
by: middletree | last post by:
Posted this to Access group, meant to do it here: I have what I call a composite table. Can't recall what they called it in database class, but it's where you take the PK of two different tables, and make a new table consisting of only those two fields. That's for normalization purposes, to resolve a many-to-many situation. Anyway, I have three dropdowns, which I intentionally gave the same name. I want people to select one, two, or...
2
2585
by: altergothen | last post by:
Hi there I am a newbie to ASP.Net - Please Help! I am trying to insert the values of my variables into a database. If I try the following it works perfectly: string insertQuery = "INSERT into test(name,surname,email) VALUES('Bob', 'Sly', 'bobsly@yahoo.com')"; but instead of inputing the values directly, I want to insert them as variables like so:
4
1332
by: thebison | last post by:
Hi all, I hope someone can help with this relatively simple problem. I am building a timesheet application using ASP.NET C# with Visual Studio 2003.As it is only a protoype application, my database has been made in MSDE. I have a 'Create Resource' page where new employees are added to the database. On my data-entry form I capture all the standard details for the Resource table. I have two drop down boxes which are data bound and
2
1534
by: Krishna | last post by:
Hi, I have developed a for dataentry by using datagird in C# windows application, I am using combocolumns, textbox columns for the same, two readonly textboxcolumns for those readonly columns i will assign the default value through nulltextproperty. I am getting all these fine it is inserting,updating without any problem. But while inserting new rows it is not inserting values related to that readonly textboxes, can some one help me...
0
1267
by: invy | last post by:
Hi, I'm a newbie to SQL SERVER world. My program(writen in Pro*C) uses both SQLAIW32.DLL and SQLAKW32.DLL libraries. We have two versions. ie, V1 and V2 with 2 pairs of theses DLLs. My problem is when i execute INSERT statment with Date functions (like SELECT getdate()), from V1 it is INSERTING with time seconds-millisecs . But in V2 it is not giving seconds, like "Nov 20 2006 5:55PM ". (I had observed that Select getdate() function...
8
3855
by: Godzilla | last post by:
Dear all, I cannot find a solution for my problem with inserting a blob object (>4000 in length) into an ORACLE database via ODBC. I have tried the two ways of inserting the blob object (a zip file): 1)
0
1767
by: gp | last post by:
I am and have been using PDO for about a year now...and have finally gotten around to solving the "DB NULL value" issues I ran into early on... I am looking for suggestions and techniques to deal with inserting DB NULL values into my MySQL 5.x DB Tables....I am running PHP 5.2.x on BSD 6.x with Apache 2.2.x.... As mentioned I am writing all my web apps using the PDO extension to connect and operate on the database. I realized early...
1
1056
by: arial | last post by:
I have two problem. 1) My insert statement here is not working. It is not inserting value into the database. I am not getting any error message but I can not figured out why it is not inserting the value into database. Please help me it is very urgent. Thank You,
6
1898
by: Bunty | last post by:
I want to insert values in the database.If i insert values one by one then it works till 4 or 5 fields then after it gives error.In my database there are more than 20 field.Pls help me.
2
3097
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography section: Discography --------------------- DiscID
0
10350
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10097
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8983
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7505
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.