Programming and Animation
Programming and animation ideas, articles, tutors, scripts, plugins in the 3d
-
[lang_en]STL Vector & Map element removing[/lang_en][lang_ru]Удаление элемента в STL Map и Vector[/lang_ru]
Дата: Август 17th, 2009 Neill Комментариев нет[lang_ru]Есть небольшая особенность, которую надо помнить при удалении элемента в векторе и ассоциативном контейнере (map)
Допустим есть такая ситуация, запускаем цикл по элементам через итератор и по некоторому критерию если элемент не подходит, его нужно удалить.
Для вектора это будет так:[/lang_ru]
[lang_en]
There is a small feature to be borne in mind when you remove an element in the vector and map.
Suppose there is such a situation, we start to cycle through the elements by iterator, and some of the criteria if the item is not suitable, it should be removed.
For a vector it will be as follows:
[/lang_en]1
2
3
4tempIter = Iter;
lVector.erase(Iter)
Iter = tempIter;
continue;[lang_ru]А вот для контейнера так:[/lang_ru][lang_en]For a map it will be as follows: [/lang_en]
Программирование C++, Map, STL, Tips, Vector1
2
3
4
5tempIter = Iter;
tempIter++;
lMap.erase(Iter)
Iter = tempIter;
continue;Добавить комментарий


Свежие комментарии