展开全部
list容器不提供 at() 和 操作符 operator[] ,对容器中元素的访问有些不便,但是我们可以使用迭代器进行元素的访问,例子如下:
#include <iostream>#include <list>
#include <algorithm>
using namespace std; void print(double& Ele){
cout<<Ele<<",";} int main(){ list<double> mylist;
mylist.push_back(11.1); mylist.push_back(22.2);
mylist.push_back(33.3); mylist.push_back(44.4);
int count=mylist.size();
for_each(mylist.begin(),mylist.end(),print); //for_each遍历mylist cout<<endl; list<double>::iterator Iter_S;
Iter_S=mylist.begin();
cout<<"The Second element is "<<*(++(++Iter_S))<<endl;
return 0;}
#include <iostream>#include <list>
#include <algorithm>
using namespace std; void print(double& Ele){
cout<<Ele<<",";} int main(){ list<double> mylist;
mylist.push_back(11.1); mylist.push_back(22.2);
mylist.push_back(33.3); mylist.push_back(44.4);
int count=mylist.size();
for_each(mylist.begin(),mylist.end(),print); //for_each遍历mylist cout<<endl; list<double>::iterator Iter_S;
Iter_S=mylist.begin();
cout<<"The Second element is "<<*(++(++Iter_S))<<endl;
return 0;}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询