title: Converting a string to a double c++
body: <p>This code reads the first line of some data I have in .txt file, 
  this first line value is '6.0', im reading the rest of the data later on in a loop, my question is how can I convert 'line' (a string) to a double (I would call 'instances') so that I can use it later in the program? It needs to be a double so I can do some calculations later with other double types. Probably a very simple solution, thanks in advance.</p>
  
  <p>NOTE: I have tried using: </p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  double instances = atof(line.c_str());
  </code></pre>
  
  <p>But it returns 0 not the correct value '6.0'</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  int main()
  { 
      string line;
      ifstream infile ("data2.txt");
      if (infile.is_open())
      { 
          getline (infile,line);    
          cout &lt;&lt; line &lt;&lt; '\n';
          infile.close();
      }
      ...
  }
  </code></pre>