#include
#include
using namespace std;
struct man{
int ID;
string name;
int age;
}ap, bp;
int main()
{
list Ltest;
man p_sruct;
list::iterator iter;
ap.age = 18;
ap.ID = 1;
ap.name = "lhonw";
bp.age = 100;
bp.ID = 5;
bp.name = "liuz";
Ltest.push_back(ap);
Ltest.push_back(bp);
//list的front方法是返回list中节点保存的类型
//这里保存的是结构体,所以返回的是结构体
p_sruct = Ltest.front();
for(iter = Ltest.begin(); iter != Ltest.end(); iter++)
{
cout << iter->age << endl;
//把第一个元素从list中弹出
if(iter->age == 18)
{
Ltest.pop_front();
}
}
for(auto iter = Ltest.begin(); iter != Ltest.end(); iter++)
{
cout << "2: " << iter->age << endl;
}
//结构体对象获取元素用点运算符
cout << "baocun: " << p_sruct.age << endl;
return 0;
}