title: Converting a string to a number in C++
body: <p>I'm seeing a lot of options for converting a string to a number in C++.</p>
  
  <p>Some of which are actually recommending the use of standard C functions such as <code>atoi</code> and <code>atof</code>.</p>
  
  <p>I have not seen anyone suggesting the following option, which relies solely on C++ STL:</p>
  
  <pre><code>int Str2Num(const string&amp; str) // can be called with a 'char*' argument as well
  {
      int num;
      istringstream(str)&gt;&gt;num;
      return num;
  }
  </code></pre>
  
  <p>Or more generally:</p>
  
  <pre><code>template &lt;typename type&gt;
  type Str2Num(const string&amp; str) // can be called with a 'char*' argument as well
  {
      type num;
      istringstream(str)&gt;&gt;num;
      return num;
  }
  </code></pre>
  
  <p>What are the disadvantages in the above implementation?</p>
  
  <p>Is there a simpler / cleaner way to achieve this conversion?</p>