共用方式為


list::end

傳回迭代器,其定址清單中最後一個元素的後接位置。

const_iterator end( ) const; iterator end( );

傳回值

雙向迭代器,其定址清單中最後一個元素的後接位置。 如果清單是空的,則 list::end == list::begin。

備註

end 用來測試迭代器是否已達到其清單的結尾。

範例

// list_end.cpp
// compile with: /EHsc
#include <list>
#include <iostream>

int main( ) 
{
   using namespace std;
   list <int> c1;
   list <int>::iterator c1_Iter;
   
   c1.push_back( 10 );
   c1.push_back( 20 );
   c1.push_back( 30 );

   c1_Iter = c1.end( );
   c1_Iter--;
   cout << "The last integer of c1 is " << *c1_Iter << endl;

   c1_Iter--;
   *c1_Iter = 400;
   cout << "The new next-to-last integer of c1 is "
        << *c1_Iter << endl;

   // If a const iterator had been declared instead with the line:
   // list <int>::const_iterator c1_Iter;
   // an error would have resulted when inserting the 400

   cout << "The list is now:";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
}
  

需求

標頭:<list>

命名空間: std

請參閱

參考

list 類別

標準樣板程式庫