front
Da cppreference.com.
Sintassi:
#include <vector> T& front(); const T& front() const;
La funzione front() ritorna una reference al primo elemento del vettore. front() gira in tempo costante.
Per esempio, il codice seguente usa un vettore e l'algoritmo sort() per mostrare la prima parola in ordine alfabetico tra quelle digitate dall'utente.
vector<string> words; string str; while( cin >> str ) words.push_back(str); sort( words.begin(), words.end() ); cout << "In alphabetical order, the first word is '" << words.front() << "'." << endl;
Se la seguente frase viene data come input:
now is the time for all good men to come to the aid of their country
...l'output è il seguente:
In alphabetical order, the first word is 'aid'.
Argomenti collegati: back