Skip to content

Instantly share code, notes, and snippets.

@Liam0205
Created October 25, 2017 10:50
Show Gist options
  • Save Liam0205/fc65d05c266b785938326fba4dd796e2 to your computer and use it in GitHub Desktop.
Save Liam0205/fc65d05c266b785938326fba4dd796e2 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <unordered_set>
#include <string>
#include <algorithm>
const std::unordered_set<std::string> replace_str_set{",", "."};
bool IsReplaceStr(const std::string& str) {
return (replace_str_set.find(str) != replace_str_set.end());
}
int main() {
std::vector<std::string> str_vec{"a", ",", "b", ".", "c"};
std::cout << "before replace: " << std::endl;
for (auto it = str_vec.begin(); it != str_vec.end(); it++) {
std::cout << *it << ' ';
}
std::cout << std::endl;
str_vec.erase(std::remove_if(str_vec.begin(), str_vec.end(), IsReplaceStr), str_vec.end());
std::cout << "after replace: " << std::endl;
for (auto it = str_vec.begin(); it != str_vec.end(); it++) {
std::cout << *it << ' ';
}
std::cout << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment