0

I'm a beginner in computer science learning c++.

Every attempt that I make to open a file in my program and read the information into a structure does not work.

Here is what I have written in the function.

void getMemberInfo(Payment member[])
{
    ifstream file;
    file.open("information.txt", ios::in);
    int i = 0;

    if (!file)
       cout << "\n Error opening file!\n\n";

    else
    {
        while (!file)
        {
            file >> member[i].ID;
            file.getline(member[i].name, 30, '\n');
            member[i].member_name = member[i].name;
            file >> member[i].payment_due;
            i++;

            if (file.eof())
            break;
    }
}

file.close();
}

Any help is appreciated. I'm kind of at a loss of what's wrong.

j.pebbles
  • 3
  • 1

1 Answers1

-3

The error is in the while condition. Just change the condition and it should work

// Instead of !file, use !file.eof()
while (!file.eof())