I need to read data from a file into an array of structures, here is my code — I recognize the length of the file (the number of lines) and then read it, but I do not get what I need at the output, what's the problem?

int countLine = 0; string line; ifstream base(pchMessage); while (getline(base, line)) ++countLine; Student *student = new Student[countLine]; int i = 0; while (base) { base >> student[i].id >> student[i].name >> student[i].surname >> student[i].rating; i++; } base.close(); 

in my file:

 111 aaa aaa 90 222 bbb bbb 72 

Reads from file:

 -842150451 -6.27744e+66 -842150451 -6.27744e+66 

What am I doing wrong?

    1 answer 1

    Well, then after you

     while (getline(base, line)) 

    came to the end of the file - what can you read there? Go back to the beginning of the file to read again.

    • Thanks, I forgot about this moment, the issue is resolved) - David Russel