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

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

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

## begin

Syntax:

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

The function begin() returns an iterator to the first element of the set. begin () should run in constant time.

For example, the following code uses begin() to initialize an iterator that is used to enumerate a set:

         // 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 set
         set<char>::iterator theIterator;
         for( theIterator = charSet.begin(); theIterator != charSet.end(); theIterator++ ) {
           cout << *theIterator;
         }
         // output is " HTehlor"

Related Topics: end, rbegin, rend

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