Skip to content

Instantly share code, notes, and snippets.

@yasuharu519
Last active August 29, 2015 14:13
Show Gist options
  • Save yasuharu519/2045e325d7fb0643e266 to your computer and use it in GitHub Desktop.
Save yasuharu519/2045e325d7fb0643e266 to your computer and use it in GitHub Desktop.
algorithmヘッダを使ったremoveの使用例
#include <iostream>
#include <vector>
static void print_vector(const std::vector<int>& v)
{
std::cout << "----- vector start -----" << std::endl;
for(const auto& i : v)
{
std::cout << i << " ";
}
std::cout << std::endl;
std::cout << "----- vector end -----" << std::endl;
}
int main()
{
std::vector<int> v{1, 2, 3, 4, 5, 6};
print_vector(v);
int target = 5;
v.erase(std::remove(v.begin(), v.end(), target), v.end());
print_vector(v);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment