Hi,
i'm learning file creating and reading and i ran into a problem when i create a file with input using a loop i end up with an extra line at the end of the file and when reading the file i always get the last line repeated twice the only thing that helped was going to the file deleting that extra line but i was wondering is there a way around this?
here is the two loops i'm using to create and read the file, i also tried to use while(inFile.good()) instead of the eof() as some suggested from my google search but that didn't help
// loop for writing data
for (int i = 1; i < 11; ++i)
{
cout << "Enter a number: ";
cin >> number;
outFile << number << endl;
}
// loop for reading the data
while (!inFile.eof())
{
inFile >> number;
total += number;
count++;
cout << number << endl;
}
thanks in advance!