#include<iostream>
#include<list>
#include<string>
using namespace std;
//赋值和交换
void printList(const list<int>& L)
{
for (list<int>::const_iterator it = L.begin(); it != L.end(); it++)
{
cout << *it << " ";
}
cout << endl;
}
void test01()
{
//创建list容器
list<int>L1;
//添加数据
L1.push_back(10);
L1.push_back(20);
L1.push_back(30);
L1.push_back(40);
//遍历容器
printList(L1);
//判断容器是否为空
if (L1.empty())
{
cout << "L1为空" << endl;
}
else
{
cout << "L1不为空" << endl;
cout << "L1的元素个数为:" << L1.size() << endl;
}
//重新指定大小
L1.resize(10, 1000);
printList(L1);
L1.resize(2);
printList(L1);
}
int main()
{
test01();
system("pause");
return 0;
}
03_list容器_大小操作
最新推荐文章于 2024-10-13 21:35:06 发布