stl:set:begin

C++ Reference

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