fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <iterator>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10. std::vector<std::string> names = {"abc", "123", "Joe"};
  11. cout << "The number of names is " << names.size() << "\n";
  12. copy(names.begin(), names.end(), ostream_iterator<string>(cout, ", "));
  13. cout << "\nI will now erase the name 123: " << "\n";
  14. string delete_contact = "123";
  15. names.erase(std::remove(names.begin(), names.end(), delete_contact), names.end());
  16. cout << "The number of names is " << names.size() << "\n";
  17. copy(names.begin(), names.end(), ostream_iterator<string>(cout, ", " ));
  18. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
The number of names is 3
abc, 123, Joe, 
I will now erase the name 123: 
The number of names is 2
abc, Joe,