如何显示stl中list的指定元素
1个回答
展开全部
LIST<int> the_LIST;
LIST<int>::iterator the_iterator;
for( int i=0; i < 10; i++ )
the_LIST.push_back(i);//将list存入10个元素
int total = 0;
the_iterator = the_LIST.begin();//将LIST第一个指针给交给the_iterator
while( the_iterator != the_LIST.end() ) {然后通过the_iterator遍历list
total += *the_iterator;
the_iterator++;
}
LIST<int>::iterator the_iterator;
for( int i=0; i < 10; i++ )
the_LIST.push_back(i);//将list存入10个元素
int total = 0;
the_iterator = the_LIST.begin();//将LIST第一个指针给交给the_iterator
while( the_iterator != the_LIST.end() ) {然后通过the_iterator遍历list
total += *the_iterator;
the_iterator++;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询