title: reading data file into 2d array c++
body: <p>I have a text file with 2 columns and many rows. each column is separated by spaces. i need to read them to a 2D array for further calculations.
  my data file looks like </p>
  
  <pre><code>0.5 0.479425539
  1   0.841470985
  1.5 0.997494987
  2   0.909297427
  2.5 0.598472144
  3   0.141120008
  3.5 -0.350783228
  4   -0.756802495
  4.5 -0.977530118
  5   -0.958924275  
  </code></pre>
  
  <p>And my feeble attempt is </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;conio.h&gt;
  #include &lt;ctype.h&gt;
  using namespace std;
  
  int main () {
    char line,element;
    std::ifstream myfile ("C:\\Users\\g\\Desktop\\test.txt");
    if (myfile.is_open())
    {
      while ( myfile.good() )
      {
        getline(myfile,line);
         cout &lt;&lt; line&lt;&lt;endl;               
        _getch();
      }
      myfile.close();
  
    }
  
    else cout &lt;&lt; "Unable to open file"; 
  
    return 0;
  
  }
  </code></pre>
  
  <p>The problem is I'm not able to read them correctly.... its either reading the whole line... if I specify the delimiter as 'space' then, its not reading the next row.</p>
  
  <p>Pls point out whats wrong. and what should i do to store the data into 2d array for further calculations.
  Thank you</p>