fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. void say(vector<string> _vec, string prefix = "") {
  7. cout << prefix;
  8. if (!prefix.empty()) cout << " ";
  9. cout << "vector<string> =";
  10. for (auto & i : _vec) { cout << " " << i; }
  11. cout << endl;
  12. }
  13.  
  14.  
  15. int main() {
  16. vector<string> foo{"a", "b", "c", "d", "e"};
  17. say(foo);
  18. cout << *(foo.begin());
  19. cout << *(foo.end()-1);
  20. cout << endl;
  21.  
  22. foo.erase(foo.begin()+1);
  23. say(foo);
  24.  
  25. vector<string> mappings_{"a", "b", "c", "d", "e"};
  26. auto it = mappings_.begin();
  27. while ( it != mappings_.end() ) {
  28. auto map = *it;
  29. if ( map == "b" || map == "c" || map == "d" ) {
  30. it = mappings_.erase(it);
  31. cout << "mappings: "; for (auto & m : mappings_) { cout << m; } cout << endl;
  32. } else {
  33. ++it;
  34. }
  35. }
  36. say(mappings_, "mappings");
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0s 4264KB
stdin
Standard input is empty
stdout
vector<string> = a b c d e
ae
vector<string> = a c d e
mappings: acde
mappings: ade
mappings: ae
mappings vector<string> = a e