fork download
  1. #include <string>
  2. #include <cstdarg>
  3. #include <iostream>
  4.  
  5. std::string string_replace(std::string s, char r, int countc, ...)
  6. {
  7. char p;
  8. va_list ap;
  9. va_start(ap, countc);
  10. for(int j = 0; j < countc; ++j)
  11. {
  12. p = static_cast<char>(va_arg(ap, int));
  13. for(char &c : s)
  14. {
  15. if(c == p)
  16. {
  17. c = r;
  18. }
  19. }
  20. }
  21. va_end(ap);
  22. return s;
  23. }
  24.  
  25. int main()
  26. {
  27. std::cout << string_replace("aeiou and sometimes y", 'z', 5, 'a', 'e', 'i', 'o', 'u') << std::endl;
  28. }
  29.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
zzzzz znd szmztzmzs y