title: Convert only digits to int in a std::string
body: <p>I'm trying to convert only the digits from a string to an int vector, but that gives me the ASCII codes for numbers 0 to 9 instead.</p>
  
  <p>Is there any way to convert only the digits to integers? I guess I'll have to use a char array since atoi() don't work with std::string and the c_str() method don't work for every character, only the entire string.</p>
  
  <pre><code>#include &lt;cctype&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  int main() {
      string chars_and_numbers = "123a456b789c0";
      vector&lt;int&gt; only_numbers;
  
      for (int i = 0; i &lt; chars_and_numbers.length(); i++) {
          if (isdigit(chars_and_numbers[i])) {
              cout &lt;&lt; chars_and_numbers[i] &lt;&lt; " ";
              only_numbers.push_back(int(chars_and_numbers[i]));
          }
      }
  
      cout &lt;&lt; endl;
  
      for (vector&lt;int&gt;::iterator i = only_numbers.begin(); i != only_numbers.end(); i++) {
          cout &lt;&lt; *i &lt;&lt; " ";
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>1 2 3 4 5 6 7 8 9 0
  49 50 51 52 53 54 55 56 57 48
  </code></pre>