fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <cctype>
  5.  
  6.  
  7. bool is_valid_word(const std::string& word)
  8. {
  9. return std::all_of(word.begin(), word.end(), isalpha);
  10. }
  11.  
  12. int main()
  13. {
  14. std::string word;
  15. std::cin >> word;
  16. while(!is_valid_word(word)) {
  17. std::cout << word << " is not a valid word\n";
  18. std::cin >> word;
  19. }
  20. std::cout << word << " is valid!";
  21. }
  22.  
Success #stdin #stdout 0s 3476KB
stdin
arg21
hello
stdout
arg21 is not a valid word
hello is valid!