|
From: Роман Д. <DXD...@ya...> - 2009-09-09 21:51:06
|
TSalm <TS...@fr...> писал(а) в своём письме Thu, 10
Sep 2009 01:29:23 +0400:
>> TSalm,
>>
>> This is a much general C++ question rather than that about MinGW. I
>> think the newsgroup comp.lang.c++ would be better.
>>
>> It is not safe to delete an element of a map before using the iterator
>> pointing to it. One of my methods may like this:
>>
>> for (map<string, string> it = myMap.begin(); it != myMap.end(); )
>> {
>> if (it->first == "2") // condition for deleting
>> {
>> map<string, string> toDel = it;
>> it++;
>> myMap.erase(toDel);
>> }
>> else
>> {
>> it++;
>> }
>> }
> Thanks, this work perfectly !
> And thanks too for your advice about comp.lang.c++.
Also of note is that in C++9x you will likely be able to delete by saying
"it = myMap.erase(it)", as the definition of erase is amended to make it
return an iterator to the next element. Until then, do the above.
Roman.
|