Вернуть струтуру из функции

Мне нужно вернуть структуру из одной функции в другую. Сначала вызывается функция SelectStudents, она вызывает OpenFile. OpenFile возвращает структуру, но лишь последнюю запись, мне нужно все записи вернуть. Вот код структуры:

struct Stud
{
    string Fio;
    string Group;
    int AverageScore;
    int Salary;
};

Stud OpenFile(string path, bool read){
        string data, info, AverageScore, Salary;
        int i = 0, am = 0;
        ifstream in(path);
        if (!in.is_open()) { cout << "File cant be open!\n"; system("pause"); }
        else
        {
            am = RowCount(am, in);
            Stud *st = new Stud[am];
            if (read) cout << "No:" << setw(10) << "FIO" << setw(30) << "Group" << setw(15) << "Av. Score" << setw(10) << "Salary\n";
            while (getline(in, data))
            {
                istringstream iss(data);
                getline(iss, st[i].Fio, ':'); getline(iss, st[i].Group, ':');
                getline(iss, AverageScore, ':'); getline(iss, Salary, ':');
                st[i].AverageScore = atoi(AverageScore.c_str());
                st[i].Salary = atoi(Salary.c_str());
                if (read) cout << i << setw(30) << st[i].Fio << setw(11) << st[i].Group << setw(12) << st[i].AverageScore << setw(13) << st[i].Salary << "\n";
                i++;
                info += data;
            }
            cout << "\n";
            return *st;
            delete[] st;
        }
        in.close();
    }

void SelectStudents(string path){
    int am = 0, MinSalary = 15000;

    ifstream in(path);
    if (!in.is_open()) { cout << "File cant be open!\n"; system("pause"); }
    else {
        am = RowCount(am,in);
        Stud *stud = new Stud[am];
        *stud = OpenFile(path, false);
        
        
        for (int i = 0; i < am; i++)  
            if (stud[i].Salary < MinSalary * 2) {
            cout << stud[i].Fio << endl;
            cout << stud[i].Group << endl;
            cout << stud[i].AverageScore << endl;
            cout << stud[i].Salary << endl;
            }
        delete[] stud;
    }
    in.close();
}

Ответы (0 шт):