Reading input from a text file

So I have a text file like this:
John 15 10
Jane 20 25
Dan 10 30
Sam 23 45
Ann 9 50

So far the program works, the only thing is that when I ran it, the output only reads the last line which is Ann 9 50. The program ignores the first 4 lines. Is there anything that I am doing wrong? Or should I anything?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main()
{
    ifstream input;
    ofstream output;
    
    string name;
    int w, h;
    
    input.open("Employees.txt");
    output.open("Employeesoutput.txt");
    
    if (input.fail())
    {
        cout << "Input file failed to open." << endl;
        system("pause");
        exit(0);
    }
    
    if (output.fail())
    {
        cout << "Output file failed to open." << endl;
        system("pause");
        exit(0);
    }
    
    while (input >> name >> w >> h)
    {
        getline(input, name);
    }
        output << setw(5) << name << setw(5) << w << setw(5) << h << endl;
    
    system("pause");
    return 0;
}
Place output inside the while loop.
Topic archived. No new replies allowed.