Varianti

begin

Da cppreference.com.
Versione del 5 mag 2012 alle 00:27 di P12bot (discussione | contributi) (r2.7.3) (Bot: Aggiungo en, ja, pl, pt, ru)

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;
     }

Argomenti correlati: end, rbegin, rend