◐ Shell
clean mode source ↗

std::array::front - cppreference.com

Da cppreference.com.

Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.

La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui.

Click here for the English version of this page

<metanoindex/>

<tbody> </tbody>

reference front();

(dal C++11)

const_reference front() const;

(dal C++11)

Restituisce un riferimento al primo elemento nel contenitore.

Original:

Returns a reference to the first element in the container.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Chiamare front su un contenitore vuoto non è definito.

Original:

Calling front on an empty container is undefined.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Parametri

(Nessuno)

Original:

(none)

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Valore di ritorno

riferimento al primo elemento

Original:

reference to the first element

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Complessità

Constant

Original:

Constant

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Note

Per un c contenitore, il c.front() espressione è equivalente a *c.begin().

Original:

For a container c, the expression c.front() is equivalent to *c.begin().

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Esempio

Il codice seguente utilizza front per visualizzare il primo elemento di un std::array<char>:

Original:

The following code uses front to display the first element of a std::array<char>:

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <array>
#include <iostream>
 
int main()
{
    std::array<char> letters {'o', 'm', 'g', 'w', 't', 'f'};
 
    if (!letters.empty()) {
        std::cout << "The first character is: " << letters.front() << '\n';
    }  
}

Output:

See also