title: How to read from a text file and split it into values in C++
body: <p>This is my text file (<code>mytext.text</code>):</p>
  <pre>
  rho_0,10
  kp_0,8
  Beta_kp,6
  x_min,5
  x_max,8
  y_min,9
  y_max,5
  z_min,4
  z_max,7
  </pre>
  <p>I want to read from this text file line by line, and store each value in the parameter at the same line.</p>
  <p>For example, for the first line, store <code>10</code> in <code>rho_0</code>.</p>
  <p>I have written this code:</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
      
  using namespace std;
      
  int main ()
  {
      string line;
      ifstream myfile(&quot;mytext.txt&quot;);
      
      if (myfile.is_open())
          while (getline(myfile, line))
          {
              cout &lt;&lt; line &lt;&lt; endl;
          }    
      }
  </code></pre>
  <p>But I don't think it will save the value for the corresponding parameter.</p>
  <p>I know that I should split each line by delimiter, and then convert string to <code>double</code> (<code>float</code>), but I don't know how to implement it for each line.</p>