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?