title: C++: Checking whether a string character is a digit using isdigit. .
body: <p>I am reading input for my program in a loop using getline.</p>
  
  <pre><code>    string temp(STR_SIZE, ' ');
      string str_num(STR_SIZE, ' ');
      ...
      getline(cin, temp, '\n');
  </code></pre>
  
  <p>After which, I use a function to find the next delimiter(white space) and assign all the characters before the white space to str_num. Looks something like this:</p>
  
  <pre><code>    str_num.assign(temp, 0, next_white_space(0));
  </code></pre>
  
  <p>I have verified that this works well. The next step in my solution would be to convert str_num to an int(this part also works well), but I should check to make sure each character in str_num is a digit. Here's the best of what I've tried:</p>
  
  <pre><code>    if(!isdigit(str_num[0] - '0')) {
          cout &lt;&lt; "Error: Not an appropriate value\n";
          break; /* Leave control structure */
      }
  </code></pre>
  
  <p>For some reason, This always prints the error message and exits the structure. 
  Why is that?
  I've used operator[] for string objects before, and it seemed to work well. But, here, it's totally messing me up.</p>
  
  <p>Thanks.</p>