title: How to get doubles from text c++
body: <p>I have a text document which looks something like this:</p>
  
  <pre><code>user_name1 1.575
  user_name2 3.636
  user_name3 2.647
  user_name4 5.532
  user_name5 4.253
  </code></pre>
  
  <p>What i am trying to do is, to get these numbers from .txt file into console and save them as variables. I know how to read .txt file in console and I found some answers here how to get each line separately as strings, but i can't get these doubles. Is there some kind of function or whatsoever that goes through strings and finds numbers?</p>
  
  <p>I tried with this:</p>
  
  <p>1) get string of each line
  2) loop through them and check ASCII code and if it is a number I saved next 3 or 4 charachters</p>
  
  <p>But its not working very well. Thanks for your help in advance.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>string line;
  
  ifstream banka ("banka.txt");
  
  double numbers[5];
  if(banka.is_open()) {
      for(int i=0; i&lt;5; i++) {
          getline(cin,line);
          size_t space=line.find(' ');
          string numStr=line.substr(space+1);
          double num = stod(numStr);
          numbers[i]=num;
  
      }
      banka.close();
  }
  else {
      cout&lt;&lt;"Unable to open file."&lt;&lt;endl;
  }
  </code></pre>