Advertisement
kej

Untitled

kej
Feb 19th, 2021
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. using namespace std;
  5. int main()
  6. {
  7. int i, count;
  8. int counter = 0;
  9. string str, word;
  10. char ch;
  11. cout << "String:\n";
  12. getline(cin, str);
  13. cout << "Letter:\n";
  14. cin >> ch;
  15. stringstream words(str);
  16. while (words >> word)
  17. {
  18. i = 0;
  19. count = 0;
  20. while (word[i])
  21. {
  22. if (word[i] == ch)
  23. {
  24. count++;
  25. counter++;
  26. break;
  27. }
  28. i++;
  29.  
  30. }
  31. cout << word << " " << count << endl;
  32. }
  33. cout << endl << "Total: " << counter << endl;
  34. system("pause");
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement