//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; }
一个关于list容器的小程序
猜你喜欢
转载自blog.csdn.net/caokun_8341/article/details/79069326
今日推荐
周排行