首页 / C++ / c++ stl list使用总结(转)
c++ stl list使用总结(转)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c++ stl list使用总结(转),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2506字,纯文字阅读大概需要4分钟。
内容图文
转自:http://blog.csdn.net/nupt123456789/article/details/8120397
#include <iostream> #include <list> #include <string> usingnamespace std; class Student{ private: int ID; string Name; public: Student(int ID,string Name) { this->ID=ID; this->Name=Name; } int getID() { return ID; } string getName() { return Name; } }; int main() { // create an empty list (of zero size) capable of holding doubles list<double> list0; cout << "Size of list0 is " << list0.size() << endl; // create a list with 5 empty elements list<double> list1(5); cout << "Size of list1 is " << list1.size() << endl; // create a list with 5 elements, each element having the value 10.2 list<double> list2(5, 10.2); cout << "list2: "; list<double>::iterator it; for(it = list2.begin(); it != list2.end(); ++it) cout << *it << ""; cout << endl; // create a list based on an array of elements // only the first 5 elements of the array are copied into the vectordouble array[8] = {3.45, 67, 10, 0.67, 8.99, 9.78, 6.77, 34.677}; list<double> list3(array, array + 5); cout << "list3: "; for(it = list3.begin(); it != list3.end(); ++it) cout << *it << ""; cout << endl; // use the copy constructor to copy list3 list into list3copy list list<double> list3copy(list3); cout << "list3copy: "; for(it = list3copy.begin(); it != list3copy.end(); ++it) cout << *it << ""; cout << endl; // assign 5 values of 10.2 to the list list<double> list4; list4.assign(5, 10.2); cout << "list4: "; for(it = list4.begin(); it != list4.end(); ++it) cout << *it << ""; cout << endl; //定义自己的数据类型 list<Student> list5; Student stu1(1,"ZhengHaibo"); Student stu2(2,"nupt"); list5.push_back(stu1); list5.push_back(stu2); list<Student>::iterator iter_stu; cout << "list5: "<<endl; for (iter_stu=list5.begin();iter_stu!=list5.end();iter_stu++) { cout<<"ID:"<<iter_stu->getID()<<" Name:"<<iter_stu->getName()<<endl; } return0; // Output // Size of list0 is 0 // Size of list1 is 5 // list2: 10.2 10.2 10.2 10.2 10.2 // list3: 3.45 67 10 0.67 8.99 // list3copy: 3.45 67 10 0.67 8.99 // list4: 10.2 10.2 10.2 10.2 10.2 //list5: //ID:1 Name:ZhengHaibo //ID:2 Name:nupt }
上面只是一点,原文很多
vector的文章http://blog.csdn.net/nupt123456789/article/details/7482923
原文:http://www.cnblogs.com/qbmiller/p/3968417.html
内容总结
以上是互联网集市为您收集整理的c++ stl list使用总结(转)全部内容,希望文章能够帮你解决c++ stl list使用总结(转)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。