473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Map will insert a new value when i request the value of a non existing key

Hey,

I run into the following problem:

I have a map:
map<string,*ofstream> FILEHANDLES
map<string,ofstream*>::iterator FILEHANDLES_it;

I fill the map in a loop with a certain number of values, let's say 3, with the key the filename and the value the pointer to a file in memory.
Let's say that after my loop the map contains the following values:
key | value
"afilename.dat" | 8x1645497
"bfilename.dat" | 8x4651318
"cfilename.dat" | 8x1978465


When I want to use an item I do the following:
ofstream *myFilePointer;

myFilePointer = FILEHANDLES["afilename.dat"];
myFilePointer will contain the value: 8x1645497
..
myFilePointer = FILEHANDLES["bfilename.dat"];
myFilePointer will contain the value: 8x4651318
..
myFilePointer = FILEHANDLES["cfilename.dat"];
myFilePointer will contain the value: 8x1978465

which works fine.

Except when I request the filehandle of a filename which isn't in the map, like
myFilePointer = FILEHANDLES["notinthemap.dat"];

When I do this, suddenly my map will contain 4 items instead of three.
The key of this item is an empty string "" and the value is a null pointer.

Why?
Feb 26 '08 #1
2 1389
When I do this, suddenly my map will contain 4 items instead of three.
The key of this item is an empty string "" and the value is a null pointer.
By the way, the key is not an empty string but contains the filename "notinthemap.dat".
Feb 27 '08 #2
Okay,

so the operator [] will also insert the value if it isn't in the map.

Problem solved.

This post can be closed.
Feb 27 '08 #3

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

Similar topics

6
by: Reply-Via-Newsgroup Thanks | last post by:
Gentle People, I think I read some where on how to do this, maybe I'm wrong. I'm working on someone elses PHP code which updates an existing database - One of the programmers used to generate...
1
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware ...
3
by: Reply-Via-Newsgroup Thanks | last post by:
Gentle People, I think I read some where on how to do this, maybe I'm wrong. I'm working on someone elses PHP code which updates an existing database - One of the programmers used to generate...
3
by: Dave | last post by:
I have an old web app that ues an Access database and ASP 3.0. I need to build an INSERT statement based on the contents of a form. What is the best way to handle blank text boxes that are...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.