fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int CountChar( std::string text, std::string text_char ) {
  5. int res = 0;
  6. for( size_t p = 0; ( p = text.find( text_char, p ) ) != std::string::npos; ++res )
  7. p += text_char.length();
  8. return res;
  9. }
  10.  
  11. int main() {
  12. std::cout << CountChar("Hello_|_Poppy_|_", "_|_") << std::endl;
  13. }
  14.  
Success #stdin #stdout 0.01s 5428KB
stdin
Standard input is empty
stdout
2