fork(2) download
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <assert.h>
  5.  
  6. void RemoveCharacterFromString(char character_for_remove, std::string &string) {
  7. auto it = std::remove_if(std::begin(string), std::end(string),
  8. [=](char c) { return c == character_for_remove; });
  9. string.erase(it, std::end(string));
  10. }
  11.  
  12. void RemoveAllCharactersInRangeFromString(char from, char to,
  13. std::string &string) {
  14. assert(from <= to);
  15. for (auto curr_character = from; curr_character <= to; ++curr_character) {
  16. RemoveCharacterFromString(curr_character, string);
  17. }
  18. }
  19.  
  20. int main() {
  21. std::string string = "aaa bbb ccc ddd ccc fff eee ggg fff";
  22. RemoveAllCharactersInRangeFromString('c', 'f', string);
  23. std::cout << "after remove: " << string << '\n';
  24. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
after remove: aaa bbb      ggg