#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <List>
using namespace std;
template <class T>
void printList(const list<T>& l)
{
for (class list<T> ::const_iterator it = l.begin(); it != l.end(); it++)
{
cout << *it << " ";
}
cout << endl;
}
void test01()
{
//list的构造函数
//list<T> lst; //默认构造,list采用模板类实现
//list(begin, end); //构造函数,利用迭代器实现区间赋值
//list(n, elem); //构造函数,将n个elem赋值给本身
//list(const list & lst); //拷贝构造
list<int> l1;
l1.push_back(10);
l1.push_back(20);
l1.push_back(30);
l1.push_back(40);
l1.push_back(50);
list<int> l2(l1.begin(), l1.end());
list<float> l3(5, 100.00f);
list<float> l4(l3);
printList(l1);
printList(l2);
p
【C++】List容器的用法解析
最新推荐文章于 2024-07-02 12:52:57 发布
本文详细介绍了C++中List容器的使用方法,包括插入、删除、遍历等操作,并通过实例展示了List的运行效果,是理解C++ List容器的重要参考资料。
摘要由CSDN通过智能技术生成