list数据存取
#include <list>
#include <iostream>
using namespace std;
//list数据存取
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<int>L1;
L1.push_back(10);
L1.push_back(20);
L1.push_back(30);
L1.push_back(40);
//l1[0]不可以用[]方式访问list容器中的元素
//l1.at(0) 不可以用at方式访问list容器的元素
cout << "第一个元素为:" << L1.front() << endl;
cout << "最后一个元素:" << L1.back() << endl;
//迭代器不支持随机访问的。
list<int>::iterator it = L1.begin();
it ++;
it --;
//it = it + 1 //错误,不支持随机访问
}
int main(){
test01();
return 0;
} 相关推荐
yangkang 2020-11-09
lbyd0 2020-11-17
KANSYOUKYOU 2020-11-16
wushengyong 2020-10-28
腾讯soso团队 2020-11-06
Apsaravod 2020-11-05
PeterChangyb 2020-11-05
gyunwh 2020-11-02