fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. size_t foo(std::string const & str, char a, char b)
  5. {
  6. std::string str2{a, b};
  7. size_t res = 0;
  8. size_t found = 0;
  9. while((found = str.find(str2, found))!=std::string::npos)
  10. {
  11. ++res;
  12. found+=2;
  13. }
  14. return res;
  15. }
  16.  
  17. int main() {
  18. std::string str = "abcabcabac";
  19. std::cout << foo(str, 'a', 'b') << std::endl;
  20. return 0;
  21. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
3