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:
Output:
The last element of s1 is 3
The last element of s1 is now 2
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