I'm having a bit of an issue with a while loop in a program I'm working on. I am attempting to use a while-eof loop to read float numbers from and input file and simply rewrite those files to a created output file. My issue is that the while loop is missing the last value all the time. The test file I'm using has 4 numbers in it but it will only output the first 3 to the output file.
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
float value;
ifstream infile;
ofstream outfile;
infile.open("tax.dat");
if (infile.fail())
{
cout << "The input file cannot be located" << endl;
exit(1);
}
outfile.open("test.out", ios::out);
if (outfile.fail())
{
cout << "The output file could not be created" << endl;
exit(1);
}
infile >> value;
while (!infile.eof())
{
outfile << value;
outfile << endl;
infile >> value;
}
infile.close();
outfile.close();
system("pause");
return 0;
}