#include "iostream"
#include "vector"
#include "list"
using namespace std;
int main()
{
//1)创建一个空的list容器。
list<int> l1;
//cout<<"l1.capacity()="<<l1.capacity()<<endl;//链表没有容器说法、
cout<<"li.size()="<<l1.size()<<endl;
//(2)使用统一列表创建list容器。
list<int>l2({1,2,3,4,5,6,7,8,9,10});
for(int value :l2)//用基于的for循环遍历容器。
cout<<value<<" ";
cout<<endl;
//(3)list(const list<T>& v)//拷贝函数、
list<int>l3(l2);
for (int value:l3)
cout<<value<<" ";
cout<<endl;
//4)lis(lterator fisrt,lterator last);
list<int>l4(l3.begin(),l3.end());//用list
for (int value:l4)
cout<<"value"<<" ";
cout<<endl;
vector<int>v1={1,2,3,4,5,6,7,8,9,10};
list<int>l5(v1.begin()+2,v1.end()-3);
for (int value:l5)
cout<<value<<" ";
cout<<endl;
int a1[]={1,2,3,4,5,6,7,8,9,10};
list<int>l6(a1+2,a1+10-3);
for (int value:l6)
cout<<value<<" ";
cout<<endl;
char str[]="hello world";
string s1(str+1,str+7);
for (auto value:s1)
cout<<value<<" ";
cout<<endl;
cout<<s1<<endl;
vector<int>v2(l3.begin(),l3.end());
for (auto value:v2)
cout<<value<<" ";
cout<<endl;
}
输出:
li.size()=0
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
value value value value value value value value value value
3 4 5 6 7
3 4 5 6 7
e l l o w
ello w
1 2 3 4 5 6 7 8 9 10
发表回复