Hey
Heres what i want to do:
I want to create a map which has <string, vector<vector<int>>>.
The string is always unique.
What i need to do is, as i read each string from a file, i compare it with existing map keys to find if that string is already present.
for that i use map.find(stringname). I store the return value in an iterator
THen i check if iter == map.end() If yes then this key is not present.
if (key is not present) {
insert the key;
put the value;
}
else {
get the value;
update the value in a temp variable;
erase the previous key using map.erase(key);
insert the updated element;
map.insert();
}
The problem is :(I wrote a dummy program to find the problem)
I hav a loop which runs thrice
I have 2 stings.
In the 1st iteration i do map.find(string1)
then i compare it with map.end().
The comparison is true (thats correct)
Then i insert a key and a value.
In the 2nd iteration, I do map.find(string1)
x = (iter == map.end() )
the value of x turns out to be 0. (thats correct)
I get the value as val = map[string1]
val is a vector of vectors.
I update the value of val, and do map.erase(string1) and insert it back again using map.insert().
In the 3rd iteration, i do map.find(string2) (note this is the second string)
x = (iter == map.end() )
Surprisingly the value of x is 0 (wrong)
When i print the value of that iterator i,e, (*iter).first, it contains the second string.
How the hell did the second string get into the map??
I hav no idea abt it.
Can sum1 help??