fork(18) download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. void removeCharsFromString( string &str, char* charsToRemove ) {
  8. for ( unsigned int i = 0; i < strlen(charsToRemove); ++i ) {
  9. str.erase( remove(str.begin(), str.end(), charsToRemove[i]), str.end() );
  10. }
  11. }
  12.  
  13. int main() {
  14. //example of usage:
  15. string str = "(My)String -before";
  16. cout << str << endl; //before
  17. removeCharsFromString( str, "()-" );
  18. cout << str << endl; //after
  19. return 0;
  20. }
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
(My)String -before
MyString before