fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <cctype>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.  
  9. string name;
  10.  
  11. while (true) {
  12.  
  13. bool ok = true;
  14.  
  15. cout << "Enter your name:\n";
  16.  
  17. getline(cin, name);
  18.  
  19. size_t nameSize = name.size();
  20.  
  21. if (nameSize == 0) continue;
  22.  
  23. for (size_t i = 0; i < nameSize; ++ i) {
  24. if (
  25. !(
  26. isalpha(name[i]) ||
  27. name[i] == ' ' // || ...
  28. )
  29. ) {
  30. ok = false; break;
  31. }
  32. }
  33.  
  34. if (ok) break;
  35. }
  36.  
  37. cout << "Hello, " << name << "!" << endl;
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 3476KB
stdin
1234 :P
(an empty line follows)

Gandalf the White
stdout
Enter your name:
Enter your name:
Enter your name:
Enter your name:
Hello, Gandalf the White!