Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
C++ Vector std::remove_if
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
template<typename T>
void OutVector(vector<T>&aData) {
for (auto&x : aData) {
cout << x << ",";
}
cout << endl;
}
int main() {
vector<int> data = {
1,2,3,2,3,4,5,2,3
};
OutVector(data);
//値に2を持つ要素を削除
auto removeIt = remove_if(data.begin(), data.end(), [&](int value) {
return value == 2;
}
);
//これで初めて要素が削除される
data.erase(removeIt, data.end());
OutVector(data);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment