You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include iostream
#include algorithm
#include vector
usingnamespacestd;boolgreater6(int i) {
return (i > 6) ? true : false;
}
intmain(void)
{
vector"int" v;
v.push_back(5); v.push_back(3);
v.push_back(2); v.push_back(34);
v.push_back(3); v.push_back(355);
v.push_back(0); v.push_back(-5);
v.push_back(-11); v.push_back(36);
/* 사용 주의! remove 사용시 특정 3을 모두 지우고 전체의 size를 유지하기 위해 끝에서 부터 삭제된 만큼의 숫자를 똑같이 채운다. 그러므로 원하는 대로 벡터의 전체 사이즈도 줄고 그 벡터 내에서 특정 값만을 지우고 싶다면 다음과 같이 해야한다. 1. remove() -> end_ptr을 반환 2. end_ptr()에서 벡터의 end까지 다 지워버림 (쓸데 없이 채운 값을 지움)*//* remove */auto end_ptr = remove(v.begin(), v.end(), 3);
v.erase(end_ptr, v.end());
/* remove_if */auto end_ptr = remove_if(v.begin(), v.end(), greater6);
v.erase(end_ptr, v.end());
for (int i = 0; i < v.size(); i++) {
cout << v.at(i) << endl;
}
}