[ Web Proxy ]
URL:
Viewing: https://fr.cppreference.com/cpp/algorithm/fill_n [Back]  [Original]

std::fill_n cppreference.com
cppreference.com
Espaces de noms
Variantes

std::fill_n

De cppreference.com

<metanoindex/>

 
 
Bibliothque d'algorithmes
Fonctions
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Non-modification de la squence des oprations
Original:
Non-modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Modification de la squence des oprations
Original:
Modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Des oprations de partitionnement
Original:
Partitioning operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Oprations de tri (sur les gammes tris)
Original:
Sorting operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
is_sorted (C++11)
is_sorted_until (C++11)
sort
Oprations binaires de recherche (sur les gammes tris)
Original:
Binary search operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Dfinir les oprations (sur les gammes tris)
Original:
Set operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Oprations Heap
Original:
Heap operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Minimum / maximum de fonctionnement
Original:
Minimum/maximum operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Oprations numriques
Original:
Numeric operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Bibliothque C
Original:
C library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
<tbody> </tbody>
Dclar dans l'en-tte <algorithm>
template< class OutputIt, class Size, class T > void fill_n( OutputIt first, Size count, const T& value ); template< class OutputIt, class Size, class T > OutputIt fill_n( OutputIt first, Size count, const T& value );
(avant C++11)

(depuis C++11)
Affecte la valeur donne value les lments count premiers pas dans la gamme dbutant first si count>0. Ne fait rien autrement .
Original:
Assigns the given value value to the first count elements in the range beginning at first if count>0. Does nothing otherwise.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Paramtres

first -
le dbut de la srie d'lments modifier
Original:
the beginning of the range of elements to modify
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
count -
nombre d'lments modifier
Original:
number of elements to modify
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 affecter
Original:
the value to be assigned
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Type requirements
-
OutputIt must meet the requirements of OutputIterator.

Retourne la valeur

(Aucun) (avant C++11)
Original:
(none) (avant C++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Iterator une aprs le dernier lment affect si count>0, first autrement. (depuis C++11)
Original:
Iterator one past the last element assigned if count>0, first otherwise. (depuis C++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Complexit

Exactement missions count, pour count>0 .
Original:
Exactly count assignments, for count>0.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Mise en uvre possible

template<class OutputIt, class Size, class T>
OutputIt fill_n(OutputIt first, Size count, const T& value)
{
    for (Size i = 0; i < count; i++) {
        *first++ = value;
    }
    return first;
}

Exemple

Le code suivant utilise fill_n() d'affecter -1 au premier semestre un vecteur d'entiers:
Original:
The following code uses fill_n() to assign -1 to the first half of a vector of integers:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <algorithm>
#include <vector>
#include <iostream>
 
int main()
{
    std::vector<int> v1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
 
    std::fill_n(v1.begin(), 5, -1);
 
    for (vector<int>::iterator it = v1.begin(); it != v1.end(); ++it) {
        std::cout << *it << " ";
    }
    std::cout << "\n";
}

Rsultat :

-1 -1 -1 -1 -1 5 6 7 8 9

Voir aussi

attribue un ensemble d'lments d'une certaine valeur
Original:
assigns a range of elements a certain value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction gnrique) [edit]

Web Proxy Viewer  |  New URL  |  Original Page