2017. 1. 26. 09:39
C++ 메모
2017. 1. 26. 09:39 in 팁&테크/C & C++
1. vector 순환하며 삭제
auto i = std::begin(inv); while (i != std::end(inv)) { // Do some stuff if (blah) i = inv.erase(i); else ++i; }
for (auto it = begin(vec); it != end(vec);) { if (*it > 5) it = vec.erase(it); else ++it; }
2. 맵 순환하며 삭제
std::map::iterator itr = myMap.begin(); while (itr != myMap.end()) { if (ShouldDelete(*itr)) { std::map ::iterator toErase = itr; ++itr; myMap.erase(toErase); } else { ++itr; } }
3.