title: How to convert string to integer using stoi()?
body: <blockquote>
  <p>If there are more than 3 letters together (i.e. next to each other) from the given Alphabet Set: {a,g,w,k,l}, then your string is “BAD”. If a number is repeated more than three times, then your string is “BAD”. Print &quot;1” if string is GOOD, else print &quot;0&quot;.</p>
  </blockquote>
  <p>For the first condition, I am able to do it. But for the second condition, I am having problem with converting a string to an int. I tried using <code>stoi()</code> but I think I am not using it correctly.</p>
  <pre><code>#include&lt;bits/stdc++.h&gt;
  
  using namespace std;
  
  int main() {
  
    int t;
    cin &gt;&gt; t;
    while (t--&gt; 0) {
      string s;
      cin &gt;&gt; s;
      int ccount = 0;
  
      int arr[10] = {0,0,0,0,0,0,0,0,0,0};
      bool b = true;
      for (int i = 0; i &lt; s.size(); i++) {
        if (s[i] == 'a' || s[i] == 'g' || s[i] == 'w' || s[i] == 'k' || s[i] == 'l') {
          ccount++;
          if (ccount &gt;= 3) {
            b = false;
            break;
          }
        } else if (isdigit(s[i])) {
          ccount = 0;
          int num = stoi( &amp; s, sizeof(s) * i, 10);
          arr[num]++;
          int k = 0;
          for (k = 0; k &lt; 10; k++) {
            if (arr[k] &gt;= 3) {
              b = false;
              break;
            }
          }
        } else {
          ccount = 0;
        }
  
      }
      if (b == true) {
        cout &lt;&lt; 1 &lt;&lt; endl;
      } else {
        cout &lt;&lt; 0 &lt;&lt; endl;
      }
  
    }
    return 0;
  }
  </code></pre>
  <p>Input:</p>
  <pre class="lang-none prettyprint-override"><code>3
  qw2uha
  awkl5
  y2y2y2y2
  </code></pre>
  <p>Output:</p>
  <pre class="lang-none prettyprint-override"><code>1
  0
  0
  </code></pre>
  <p><strong>EDIT</strong>: ASCII conversion works very well.</p>
  <p>I have a not so important problem, I know we can't directly compare integers of different signedness, but still I am curious.</p>
  <pre><code>#include&lt;bits/stdc++.h&gt;
  using namespace std;
  
  int main() {
  
    int t;
    cin &gt;&gt; t;
    while (t--&gt; 0) {
      string s;
      cin &gt;&gt; s;
      int ccount = 0;
      int arr[10] = {0,0,0,0,0,0,0,0,0,0};
      bool b = true;
      for (int i = 0; i &lt; s.size(); i++) {
        if (s[i] == 'a' || s[i] == 'g' || s[i] == 'w' || s[i] == 'k' || s[i] == 'l') {
          ccount++;
          if (ccount &gt;= 3) {
            b = false;
            break;
          }
        } else if (isdigit(s[i])) {
          ccount = 0;
          int num = s[i] - '0';
          arr[num]++;
          int k = 0;
          for (k = 0; k &lt; 10; k++) {
            if (arr[k] &gt; 3) {
              b = false;
              break;
            }
          }
        } else {
          ccount = 0;
        }
      }
      if (b == true) {
        cout &lt;&lt; 1 &lt;&lt; endl;
      } else {
        cout &lt;&lt; 0 &lt;&lt; endl;
      }
    }
    return 0;
  }
  </code></pre>
  <p>I am getting this warning :</p>
  <pre class="lang-none prettyprint-override"><code>14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string&lt;char&gt;::size_type' {aka 'unsigned int'} [-Wsign-compare]
     14 |     for (int i = 0; i &lt; s.size(); i++) {
        |                     ~~^~~~~~~~~~
  ]
  </code></pre>
  <p>Is there any way to fix the warning?</p>