Last active
August 29, 2015 14:13
-
-
Save yasuharu519/2045e325d7fb0643e266 to your computer and use it in GitHub Desktop.
algorithmヘッダを使ったremoveの使用例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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