Sintassi:
#include <string> iterator begin(); const_iterator begin() const;
La funzione begin() ritorna un iteratore che punta al primo elemento della stringa.
begin() in genere ha tempo di esecuzione constante.
Ad esempio, il seguente codice utilizza begin() per inizializzare un iteratore che e' poi usato per scorrere una lista di caratteri:
// Crea una lista di caratteri list<char> charList; for( int i=0; i < 10; i++ ) { static const char letters[] = "ABCDEFGHIJ"; charList.push_front( letters[i] ); } // Stampa la lista list<char>::iterator theIterator; for ( theIterator = charList.begin(); theIterator != charList.end(); ++theIterator ) { cout << *theIterator; }