list c++ class

list c++ class

// use list with class

#include<iostream>
#include<list>

using namespace std;

class Student
{
    public:
    Student(string _name, int _id):name(_name),id(_id)
    {

    }
    ~Student(){ }
    void print()
    {
        cout<<"name: "<<name<<endl;
        cout<<"id:   "<<id<<endl;
        cout<<endl;
    }
    private:
    string name;
    int id;
};

int main()
{
    list<Student> Liste;
    list<Student>::iterator iter;
    Student *p;
    string name;
    int id;

    for(int i=0; i<3; i++)
    {
        cout<<"enter name: ";
        cin>>name;
        cout<<"enter id :";
        cin>>id;

        p=new Student(name,id);
        Liste.push_back(*p);        //add to end
    }

    p=new Student("root",1);
    Liste.push_front(*p);           //add to front

    iter=Liste.begin();
    ++iter;

    p=new Student("arayagiren",2);
    Liste.insert(iter,*p);             //baştan 2. yere eklicek

    iter=Liste.end();

    p=new Student("sonikikez",33);
    Liste.insert(iter,2,*p);            //en sona iki kez atıycak

    for(iter=Liste.begin(); iter!=Liste.end(); iter++)
    iter->print();

    return 0;
}