begin [C++ Reference]
Keywords: string,begin
Date: 2010-01-04T10:30:05-0800

## begin

Syntax:

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

The function begin() returns an iterator to the first element of the string. begin() should run in constant time. For example, the following code uses begin() to initialize an iterator that is used to traverse a list:

         // Create a list of characters
         list<char> charList;
         for( int i=0; i < 10; i++ ) {
           static const char letters[] = "ABCDEFGHIJ";
           charList.push_front( letters[i] );
         }
         // Display the list
         list<char>::iterator theIterator;
         for ( theIterator = charList.begin();
                   theIterator != charList.end();
                   ++theIterator ) {
           cout << *theIterator;
         }

Related Topics: end, rbegin, rend