Code:
#include <iostream>
#include <fstream>
//--
using std::cin;
using std::ifstream;
using std::ofstream;
using std::cout;
using std::endl;
//--
int main()
{
float test_data[4];
test_data[0] = 1.23;
test_data[1] = 2.34;
test_data[2] = 3.45;
test_data[3] = 4.56;
//**** OUTPUT TEST_DATA ****
ofstream outfile("test.txt", std::ios::out);
for(short i=0; i<4; i++)
{
outfile << test_data[i] << " ";
outfile << endl;
}
outfile.close();
//**** INPUT TEST_DATA TO SAMPLE ****
float sample[4] = {0}; //Always good to intialize arrays.
short i(0);
ifstream infile("test.txt", std::ios::in);
while(infile >> sample[i])
{
++i;
}
infile.close();
//Test
for(short i=0; i < 4; ++i)
{
cout<<sample[i]<<endl;
}
return 0;
}
There's a lot of info on streams on this forum. Just use the "search" button. There are some pretty nice things to be found.