title: Complexity of Converting String to Int in C++
body: <p>I am having trouble with converting <strong>string</strong> datatype to <strong>int</strong> in c++, I am currently using DevC++ GNU version 5.8.3 which gives an error when i use <strong>stoi</strong>() funtion. My concern is not about conversion but about the complexity and how it is done. Code Below :</p>
  
  <pre><code>#include&lt;bits/stdc++.h&gt;
  int main(){
      string s="abc";
      int i=stoi(s,NULL,16);
  }
  </code></pre>
  
  <blockquote>
    <p>Error : 'stoi' was not declared in this scope</p>
  </blockquote>
  
  <p>So, i wrote my own function, Code Below : </p>
  
  <p>String to Int :</p>
  
  <pre><code>int strtonum(string s,int length) {
      int num=0;
      for(int i=0;i&lt;length;i++)
          num=num*10+(int)s[i]-48;
      return num;
  }
  </code></pre>
  
  <p>Integer to String : </p>
  
  <pre><code>string numtostring(int number){
      int digit=floor(log10(number))+1;
      string s="";
      for(int i=0;i&lt;digit;i++){
          s+=(char)(48+number%10);
          number/=10;
      }
      reverse(s.begin(),s.end());
      return s;
  }
  </code></pre>
  
  <p>Both Functions are giving desired output, But I am worried about the complexity of Conversion.</p>
  
  <p>For String to Int it is : <strong>O(n)</strong></p>
  
  <p>For Int to String it is : <strong>O(n)+O(n/2)</strong></p>
  
  <p><strong>Q. Is there any better Solution to this problem ?</strong></p>
  
  <p><strong>Q. How Complex are the Inbuilt Function</strong></p>
  
  <p><strong>Q.How do they Convert one data type to another?</strong></p>