-
How to remove specific value in vector. 벡터 배열에서 특정 값을 지우는 방법. c++, stlProgramming 2019. 6. 12. 23:22반응형
// removes all elements with the value 5 vector.erase( std::remove( vector.begin(), vector.end(), 5 ), vector.end() );erase function -> erase from specific position to specific position.
remove function -> move specific values to the end, and return the most front index iterator of that specific values moved.
erase 함수는 (특정위치1 ~ 특정위치2) 까지 범위의 값을 지워준다.
remove 함수는 (특정위치1 ~ 특정위치2) 까지 범위의 ( value ) 를 맨 뒤쪽으로 싹 보내준 후, 맨 뒤로 몰린 것들 중에서 맨 앞의 index iterator 를 반환한다.
remove 함수로 지울 위치를 잡고 그 부분부터 erase 로 싹 지우면 벡터에서 index 값을 사용하지 않고 특정 값을 지울 수 있다.
이게 아니면, algorithm 의 find 함수로 특정 value 를 찾은 인덱스를 넣어서 지워도 무방하다.
반응형'Programming' 카테고리의 다른 글