deleting entries from the map using iterator

map<string, string> drrInternalUserStatusMap;
map<string , string>::iterator drrMapIter;
char caFleet[23];

...............
some where in the code drrInternelUserStatusMap got some entries
...............
...............

for (drrMapIter = drrInternalUserStatusMap.begin(); drrMapIter != drrInternalUserStatusMap.end(); )
{

getFleetFromUfmi(drrMapIter->second.c_str() , caFleet );
if ( !strcmp ( fleet.c_str() , caFleet ) )
{
LOG_L5 (( "\nCFL: Fleet Entry is found and deleting that fleet: %s" , caFleet ));
drrInternalUserStatusMap.erase ( tmpDrrMapIter++ );
}
else
{
drrMapIter++;
}
}



Above code is dumping core: following is that info:

#0 0x080667b9 in std::_Rb_tree_base_iterator::_M_increment (this=0xb68753b0)
at stl_tree.h:137
#1 0x08090695 in std::_Rb_tree_iterator<std::pair<std::string const, std::string>, std::pair<std::string const, std::string>&, std::pair<std::string const, std::string>*>::operator++ (
this=0xb68753b0) at stl_tree.h:207

Help me in resolving this issue.
[1225 byte] By [adapanaidu] at [2007-11-20 6:32:16]
# 1 Re: deleting entries from the map using iterator
The problem is here:
drrInternalUserStatusMap.erase ( tmpDrrMapIter++ );

You need to do this:
tmpDrrMapIter = drrInternalUserStatusMap.erase (tmpDrrMapIter);

:)

http://msdn2.microsoft.com/en-us/library/z2f3cb7h(VS.71).aspx
Zaccheus at 2007-11-9 1:16:12 >
# 2 Re: deleting entries from the map using iterator
sorry gurus,

Small correction: it is not

drrInternalUserStatusMap.erase ( tmpDrrMapIter++ );

it is

drrInternalUserStatusMap.erase ( drrMapIter++ );



i am running this program on linux OS , using g++ compiler.
adapanaidu at 2007-11-9 1:17:17 >
# 3 Re: deleting entries from the map using iterator
Then it needs to be:

drrMapIter = drrInternalUserStatusMap.erase ( drrMapIter );
Zaccheus at 2007-11-9 1:18:16 >
# 4 Re: deleting entries from the map using iterator
that is not the error. Still it is dumping. What can be reason. Help me to rectify that bug.
adapanaidu at 2007-11-9 1:19:24 >
# 5 Re: deleting entries from the map using iterator
What error are you getting now ?
Zaccheus at 2007-11-9 1:20:23 >
# 6 Re: deleting entries from the map using iterator
same coredump.
adapanaidu at 2007-11-9 1:21:19 >
# 7 Re: deleting entries from the map using iterator
Strange. I can't see anything else wrong with your code.

Is it possible that getFleetFromUfmi is corrupting the stack ?
Zaccheus at 2007-11-9 1:22:23 >
# 8 Re: deleting entries from the map using iterator
that is not the error. Still it is dumping. What can be reason. Help me to rectify that bug.Without seeing the other parts of your code (the part where you do this -- "..........."), and all of those unknown functions, and we don't have any idea of anything else in your program except you're using a map and a loop, your bug could be anywhere.

Regards,

Paul McKenzie
Paul McKenzie at 2007-11-9 1:23:28 >