ifstream mystream(file_name);
ofstream outputstream(filename, ios::out);
do {
mystream.getline(line, 100);
mystream >> country_name >> happiness_value;
total_happiness = total_happiness + happiness_value;
count++;
outputstream << country_name << " \t \t " << happiness_value << endl;
} while (!mystream.eof());
the file ifstream is reading from is a .dat file, in this format:
first 1
second 2
third 3
fourth 4
This is the exact file ifstream is opening, but for some reason when I check my output file is shows like it should except it displays "fourth 4" twice,
e.g :
fourth 4
fourth 4
Why is my loop iterating more than it should?
Don't know if it helps, but my count has been initialized as 0 and equals 5 at the end of the loop.