您的位置:首页 > 移动开发 > 微信开发

一个关于list容器的小程序

2018-01-15 22:01 183 查看
//1.1.5最简单的c++ 程序
//例1-5 一个关于list容器的小程序
#include <iostream>
#include <list>
using namespace std;
struct PERSON{
int id,sex;
double core;
void clear()
{
id = 0;
sex = 0;
core = 0;
}
};

int main()
{
PERSON temp;
list <PERSON> C1;  //声明一个list容器对象C1,容器中的元素是PERSON类型的对象
int id_temp,sex_temp,size;
double core_temp;
C1.clear();        //清空容器
int counter = 0;   //计数器
cout<<"This is a simplest C++ Example!\n"<<endl;
cout<<"任意键开始......";
cin.get();
while(counter<5)
{
cout<<"请输入ID:";
cin>>id_temp;
cout<<"请输入性别:";
cin>>sex_temp;
cout<<"请输入分数:";
cin>>core_temp;
temp.id = id_temp;
temp.sex = sex_temp;
temp.core = core_temp;
C1.push_back(temp);
memset(&temp,0,sizeof(PERSON));
counter++;
}
cout<<"按<Enter>键继续......";
cin.get();
size = C1.size();
cout<<endl;
list<PERSON>::iterator Iter;
for(Iter=C1.begin();Iter != C1.end();Iter++)
{
temp.clear();
temp = *Iter;
cout<<"ID:"<<temp.id<<",SEX:"<<temp.sex<<",Core:"<<temp.core<<endl;
}
cout<<"按任意键退出程序......"; //<<endl;
cin.get();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C list STL