如何显示stl中list的指定元素?比如显示第二个。

解决方案 »

  1.   

    遍历
    貌似list按存储顺序来遍历 
      

  2.   

      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++;
      }
      

  3.   

    但是遍历就全部显示了,我知道下面的方法:
    copy(list.begin(), list.end(), ostream_iterator<int>(cout, " "));
    这是显示所有。能不能只显示一个或几个?
      

  4.   

    list<int>m_list;
    list<int>::iterator iter;
    iter=m_list.begin();
    *(++iter)就是这了