Share via


set::end

Returns an iterator that addresses the location succeeding the last element in a set.

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

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

The last element of s1 is 3 The last element of s1 is now 2

Requirements

Header: <set>

Namespace: std

See Also

Reference

set Class

set::swap, set::begin, and set::end

Standard Template Library

Other Resources

set Members