◐ Shell
clean mode source ↗

std::vector::assign — cppreference.com

De cppreference.com

<metanoindex/>

<tbody> </tbody>

void assign( size_type count, const T& value );

(1)

template< class InputIt > void assign( InputIt first, InputIt last );

(2)

Remplace le contenu du récipient .

Original:

Replaces the contents of the container.

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

1)

remplace le contenu des copies de count value valeur

Original:

replaces the contents with count copies of value value

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

2)

remplace le contenu des copies de ceux de la gamme [first, last)

Original:

replaces the contents with copies of those in the range [first, last)

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

Paramètres

count -

la nouvelle taille du récipient

Original:

the new size of the container

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

value -

la valeur de l'initialisation des éléments de récipient avec

Original:

the value to initialize elements of the container with

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

first, last -

la plage à copier des éléments à partir

Original:

the range to copy the elements from

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

Type requirements
-InputIt must meet the requirements of InputIterator.

Complexité

1)

linéaire dans count

Original:

linear in count

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

2)

linéaire de la distance entre first et last

Original:

linear in distance between first and last

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

Exemple

Le code suivant utilise assign d'ajouter plusieurs caractères à un std::vector<char>:

Original:

The following code uses assign to add several characters to a std::vector<char>:

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

#include <vector>
#include <iostream>
 
int main()
{
    std::vector<char> characters;
 
    characters.assign(5, 'a');

    for (char c : characters) {
        std::cout << c << '\n';
    } 

    return 0;
}

Résultat :

Voir aussi