title: how do I check if all characters in a string is space or alphabet? C++
body: <p>I need to make a program which converts all letters to uppercase.</p>
  <p>But first I need to get an input from the user. And I need to check if there are characters that are not space or alphabet.</p>
  <p>This is what I tried.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cctype&gt;
  
  using namespace std;
  
  int main()
  {
  string s;
  cout &lt;&lt; &quot;Enter a string: &quot;;
  
  while (getline(cin, s)){
      for (int i = 0; i&lt;s.length(); i++){
          if ((isspace(s[i]) || isalpha(s[i]))){
              for (int i = 0; i &lt; s.length(); i++){
                  s[i] = toupper(s[i]);
              }
              cout &lt;&lt; s &lt;&lt; endl;
              return 1;
          }
          cout &lt;&lt; &quot;Invalid string. Please input only alphabets or space character. &quot; &lt;&lt; endl &lt;&lt; &quot;Enter a string: &quot;;
      }
  }
  
  //if the input value is valid convert and print
  
  return 0;}
  </code></pre>
  <p>This program successfully make error messages to pure numbers and pure question marks. But the problem is if there are invalid characters and valid characters mixed in the input, it cannot distinguish it.</p>
  <p>For example, if input is &quot;Hi?&quot;, the program thinks its a valid input. But with questions marks, the string should be invalid.</p>
  <p>I think the for statement is the problem. How can I solve this?</p>