dynamiczne przydzielanie pamięci do struktury podczas odczytu z pliku w C ++

Mam strukturę

typedef struct student
{
    char name[10];
    int age;
    vector<int> grades;
} student_t;

I piszę jego zawartość do pliku binarnego.

Piszę w różnych momentach i mam wiele danych w pliku zapisanych z tej struktury.

Teraz chcę przeczytać WSZYSTKIE dane znajdujące się w pliku binarnym do struktury. Nie jestem pewien, jak mogę przydzielić pamięć (dynamicznie) do struktury, aby struktura mogła pomieścić wszystkie dane w strukturze.

Czy możesz mi pomóc z tym.

Kod:

#include <fstream>
#include <iostream>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <iterator>

using namespace std;


typedef struct student
{
    char name[10];
    int age;
    vector<int> grades;
}student_t;

int main()
{
    student_t apprentice[3];
    strcpy(apprentice[0].name, "john");
    apprentice[0].age = 21;
    apprentice[0].grades.push_back(1);
    apprentice[0].grades.push_back(3);
    apprentice[0].grades.push_back(5);

    strcpy(apprentice[1].name, "jerry");
    apprentice[1].age = 22;
    apprentice[1].grades.push_back(2);
    apprentice[1].grades.push_back(4);
    apprentice[1].grades.push_back(6);

    strcpy(apprentice[2].name, "jimmy");
    apprentice[2].age = 23;
    apprentice[2].grades.push_back(8);
    apprentice[2].grades.push_back(9);
    apprentice[2].grades.push_back(10);

    // Serializing struct to student.data
    ofstream output_file("students.data", ios::binary);
    output_file.write((char*)&apprentice, sizeof(apprentice));
    output_file.close();

    // Reading from it
    ifstream input_file("students.data", ios::binary);
    student_t master;

    input_file.seekg (0, ios::end);
    cout << input_file.tellg();

    std::vector<student_t> s;

    // input_file.read((char*)s, sizeof(s)); - dint work

    /*input_file >> std::noskipws;
    std::copy(istream_iterator(input_file), istream_iterator(), std::back_inserter(s));*/

    while(input_file >> master) // throws error
    {
        s.push_back(master);
    }
    return 0;
}

questionAnswers(3)

yourAnswerToTheQuestion