reading numeric data from a text file in c++
<p>For example, if data in an external text file is like this:</p>

<pre><code>45.78   67.90   87
34.89   346     0.98
</code></pre>

<p>How can I read this text file and assign each number to a variable in c++?
Using ifstream, I am able to open the text file and assign first number to a variable, but I don't know how to read the next number after the spaces.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
using namespace std;
int main ()
{
    float a;
    ifstream myfile;
    myfile.open ("data.txt");
    myfile&gt;&gt;a;
    cout&lt;&lt;a;
    myfile.close();
    system ("pause");
    return 0;
}


#include &lt;iostream&gt;
#include &lt;fstream&gt;
using namespace std;
int main ()
{int data[6],a,b,c,d,e,f;
ifstream myfile;
myfile.open ("a.txt");
for (int i=0;i&lt;&lt;6;i++)
{
    myfile&gt;&gt;data[i];
    }
myfile.close();
a=data[0];
b=data[1];
c=data[2];
d=data[3];
e=data[4];
f=data[5];
cout&lt;&lt;a&lt;&lt;"\t"&lt;&lt;b&lt;&lt;"\t"&lt;&lt;c&lt;&lt;"\t"&lt;&lt;d&lt;&lt;"\t"&lt;&lt;e&lt;&lt;"\t"&lt;&lt;f&lt;&lt;"\n";
system ("pause");
return 0;}
</code></pre>
