end [C++ Reference]
Keywords: stl,set,end
Date: 2008-10-14T15:42:07-0700

[[end]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- fr
- it
- jp
- pl
- ru
- tr

## end

Syntax:

        #include <set>
        iterator end();
        const_iterator end() const;

The end() function returns an iterator just past the end of the set. Note that before you can access the last element of the set using an iterator that you get from a call to end(), you'll have to decrement the iterator first.

For example, the following code uses end() to display the set in reverse order:

         // Create a set of characters
         set<char> charSet;
         const char* s = "Hello There";
         for( int i=0; i < strlen(s); i++ ) {
           charSet.insert( s[i] );
         }
         // Display the last element of the set
         set<char>::iterator theIterator = charSet.end();
         for( theIterator = charSet.end(); theIterator != charSet.begin(); ) {
           theIterator--;
           cout << *theIterator;
         }
         // output is "rolheTH "

Related Topics: begin, rbegin, rend

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •