반응형
1. input 값
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
// index로 하나삭제
vector<int> myvec = { 1,2,3,4,5,6 };
myvec.erase(myvec.begin() + 1);
for (int i = 0; i < myvec.size(); i++) {
cout << myvec[i] << ",";
}
cout << endl;
// index로 범위삭제
myvec = { 1,2,3,4,5,6 };
myvec.erase(myvec.begin() + 3, myvec.begin() + 5);
for (int i = 0; i < myvec.size(); i++) {
cout << myvec[i] << ",";
}
cout << endl;
// 값으로 삭제
myvec = { 1,2,3,3,5,6 };
myvec.erase(remove(myvec.begin(), myvec.end(), 3), myvec.end());
for (int i = 0; i < myvec.size(); i++) {
cout << myvec[i] << ",";
}
cout << endl;
return 0;
}
2. output값
1,3,4,5,6,
1,2,3,6,
1,2,5,6,
반응형