// DAY_0425_02.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <list>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef struct student
{
char *Name; //姓名
char *Sex; //性别
int Age; //年龄
}STUDENT;
//数据类型定义
typedef list<int> ListINTtype;
typedef list<STUDENT> ListSTUDENTtype;
//迭代器定义,指针是迭代器,迭代器的区间为[begin,end).
typedef list<int>::iterator INTiter; //int数据类型list迭代器(指针)
typedef list<STUDENT>:: iterator STUDENTiter;//STUDENT数据类型list迭代器
int main(int argc, char* argv[])
{
STUDENT student1;
STUDENT student2;
STUDENT student3;
student1.Name = "Student1 ";
student1.Sex = "Female ";
student1.Age = 20;
student2.Name = "Student2 ";
student2.Sex = "Male ";
student2.Age = 21;
student3.Name = "Student3 ";
student3.Sex = "Female ";
student3.Age = 23;
//定义两种list变量
ListINTtype intlist;
ListSTUDENTtype studentlist;
studentlist.insert(studentlist.begin(), student1);
studentlist.insert(studentlist.begin(), student2);
studentlist.insert(studentlist.end(), student3);
//打印出2、 1、 3 学生信息
for (STUDENTiter iter = studentlist.begin(); iter != studentlist.end(); iter++)
{
STUDENT studentTemp = *iter;
cout << (*iter).Name << (*iter).Sex << (*iter).Age << endl;
}
for (int i = 0; i < 10; i++)
{
intlist.push_back(i);
}
//打印出0~9即所有int元素
for (INTiter iterTemp = intlist.begin(); iterTemp != intlist.end(); iterTemp++)
{
cout << *iterTemp << endl;
}
return 0;
}
STL_LIST
最新推荐文章于 2024-07-03 17:37:31 发布