C++ 标准模板库 (STL) 中的列表。我制作了以下程序,但我不知道如何制作打印列表的功能

List in C++ Standard Template Library (STL). I made the following program and I don't know how to make a function to print the list

    #include <iostream> 
    #include <list> 
    #include <iterator> 
    using namespace std;
    class Profesor
    {
        public:
        string nume, departament;
        int grad, vechime;
    
        Profesor(string n, string d, int g, int v);
    };

    
    Profesor::Profesor(string n, string d, int g, int v) {
        nume = n;
        departament = d;
        grad = g;
        vechime = v;
    }
    int main()
    {
        list <Profesor*> profi;
        Profesor* p;
        int opt;
        string nume, departament;
        int grad, vechime;
        do {

            cout << "1.Adaugare" << endl;
            cout << "Dati optiunea! " << endl;
            cin >> opt;
            switch (opt)
            {
            case 1:
                cout << "Nume:";
                cin >> nume;
                cout << "Departament:";
                cin >> departament;
                cout << "Grad:";
                cin >> grad;
                cout << "Vechime";
                cin >> vechime;
                p = new Profesor(nume, departament, grad, vechime);
                profi.push_front(p);
            default:
                break;
            }
        } while (opt);
        return 0;
    }

选项 1 是将新项目添加到列表中 这是 class 的构造函数 所以我需要一个函数来显示整个列表 ajgnsjdgn afkajkf nskjfnakfakfnaf afnakfnasdnlang akfnafdakfrnaasf asdfkasfna 广告 akjdgnakjsgsa askfnaksd asgnaskdng asdgjnsadgag

给 Profesor 添加一个函数来输出它的当前变量:

void output() const {
    cout << " * nume:        " << nume        << endl;
    cout << " * departament: " << departament << endl;
    cout << " * grad:        " << grad        << endl;
    cout << " * vechime:     " << vechime     << endl;
}

创建一个遍历列表并调用该函数的函数。
这是一个使用基于范围的 for 循环的示例:

void outputProfesors(const list<Profesor*>& profesors) {
    for (const auto& profesor : profesors) {
        profesor->output();
    }
}

呼叫outputProfesors().