c++积累(1):一个简单的list容器迭代程序

来源:互联网 发布:淘宝首页悬浮框 编辑:程序博客网 时间:2024/04/29 12:06
#include <iostream>#include <list>#include <string>/*#include <opencv2/core/affine.hpp>#include <opencv2/imgproc/imgproc.hpp>#include <opencv2/highgui/highgui.hpp>*/using namespace std;//using namespace cv;struct students{int age;string name;void clear(){age = 0;name = "Unknown";}};int main(){students temp;list<students>studentObj;studentObj.clear();int z_count = 0;int z_age;string z_name;cin.get();while(z_count < 4){cout << "Please input age: ";cin >> z_age;cout << endl;cout << "Please input name: ";cin >> z_name;temp.age = z_age;temp.name = z_name;studentObj.push_back(temp);memset(&temp, 0, sizeof(students));z_count++;}cout << "Type Enter, go on!";cin.get();int size = studentObj.size();cout << endl;list<students>::iterator zhang;for (zhang = studentObj.begin(); zhang != studentObj.end(); zhang++){temp.clear();temp = *zhang;//看来迭代器和指针都是一样的,存储的是地址cout << "age: " << temp.age << ", name: " << temp.name << endl;}return 0;}

0 0
原创粉丝点击