fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4.  
  5. int main() {
  6. std::string input = "Hello, the wonderful, the awesome and the beautiful world!";
  7. std::string to_find = "the";
  8. int foundCount = 0;
  9. std::stringstream ss( input );
  10. while ( ss.good() ) {
  11. std::string word;
  12. ss >> word;
  13. if ( word == to_find ) {
  14. foundCount++;
  15. }
  16. }
  17. std::cout << "Input: " << input << std::endl;
  18. std::cout << to_find << " found " << foundCount << " times" << std::endl;
  19. return 0;
  20. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
Input: Hello, the wonderful, the awesome and the beautiful world!
the found 3 times