fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int main() {
  5. std::string word = "strawberry";
  6. int count = 0;
  7.  
  8. for (int i = 0; i < word.length(); i++) {
  9. if (word[i] == 'r') {
  10. count++;
  11. }
  12. }
  13.  
  14. std::cout << "Number of 'r's in 'strawberry': " << count << std::endl;
  15.  
  16. return 0;
  17. }
  18.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Number of 'r's in 'strawberry': 3