set::end
傳回處理成功最後一個項目的位置中的 Iterator。
const_iterator end( ) const;
iterator end( );
傳回值
解決成功最後一個項目的位置中的雙向 Iterator。 如果這個集合是空的,然後 set::end ==set::begin。
備註
end 用來測試 Iterator 是否已到達集合的結尾。 不應該取值 end 傳回的值。
範例
// set_end.cpp
// compile with: /EHsc
#include <set>
#include <iostream>
int main( )
{
using namespace std;
set <int> s1;
set <int> :: iterator s1_Iter;
set <int> :: const_iterator s1_cIter;
s1.insert( 1 );
s1.insert( 2 );
s1.insert( 3 );
s1_Iter = s1.end( );
s1_Iter--;
cout << "The last element of s1 is " << *s1_Iter << endl;
s1.erase( s1_Iter );
// The following 3 lines would err because the iterator is const
// s1_cIter = s1.end( );
// s1_cIter--;
// s1.erase( s1_cIter );
s1_cIter = s1.end( );
s1_cIter--;
cout << "The last element of s1 is now " << *s1_cIter << endl;
}
需求
標題: <set>
命名空間: std