fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4.  
  5. std::string vowels("aeiouAEIOU");
  6.  
  7. bool contains(const std::string& s, char letter)
  8. {
  9. return s.find(letter) != std::string::npos;
  10. }
  11.  
  12. bool is_vowel(char ch)
  13. {
  14. return contains(vowels, ch);
  15. }
  16.  
  17. std::istringstream in("These are some words\n. Everyone should know them.");
  18.  
  19. int main()
  20. {
  21. std::size_t vowels = 0;
  22. char ch;
  23.  
  24. while (in >> ch)
  25. vowels += is_vowel(ch);
  26.  
  27. std::cout << "Counted " << vowels << " vowels.\n";
  28. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
Counted 15 vowels.