-1
#include <iostream>
#include <fstream>

using namespace std;

int main() {
    ifstream infile;

    int age;

    infile.open("intestfile.txt");
        if(infile){
            while(!infile.eof()) {
                infile >> age;
                cout << age << endl;
            }
        } else {
            cout << "Error opening file." << endl;
        }
    infile.close();
}

I am expecting an output like; 10 20 30 40 50 (this list displayed vertically). Why am I getting 10 20 30 40 50 50 and yet the input file has 10 20 30 40 50 only. where is the duplicate 50 coming from?

nayab
  • 2,216
  • 1
  • 15
  • 32

1 Answers1

0

i have copy your code and directly run into a terminal , but i am getting right output. i am not getting duplicate 50.

hardik gosai
  • 260
  • 2
  • 15