STL_set——set::end

来源:互联网 发布:凯文考试软件 编辑:程序博客网 时间:2024/06/16 00:18
Reference:
Returns an iterator that addresses the location succeeding the last element in a set.

Function:
const_iterator end( ) const;
iterator end( );

Return Value:
A bidirectional iterator that addresses the location succeeding the last element in a set. If the set is empty, then set::end ==set::begin.

Remarks:
end is used to test whether an iterator has reached the end of its set. The value returned by end should not be dereferenced.

Example:
#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 );   s1_cIter = s1.end( );   s1_cIter--;   cout << "The last element of s1 is now " << *s1_cIter << endl;}

Output:
The last element of s1 is 3
The last element of s1 is now 2
0 0
原创粉丝点击