fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. string str;
  7. char ch;
  8. char search;
  9. int count = 0;
  10.  
  11. cin >> search;
  12. cin >> str;
  13.  
  14. for (auto iter = str.begin(); iter != str.end(); ++iter) {
  15.  
  16. //current character
  17. ch = *iter;
  18. //cout << ch << " ";
  19. if (ch == search) {
  20. count += 1;
  21. }
  22. }
  23. cout << count << " " << search << "'s" << endl;
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5384KB
stdin
e Geek
stdout
2 e's