Espacios de nombres
Variantes
Acciones

std::fill

De cppreference.com
< cpp‎ | algorithm

 
 
Biblioteca de algoritmos
Políticas de ejecución (C++17)
Operaciones no modificadoras de secuencia
(C++11)(C++11)(C++11)
(C++17)
Operaciones modificadoras de secuencia
Operaciones en almacenamiento no inicializado
Operaciones de partición
Operaciones de ordenación
(C++11)
Operaciones de búsqueda binaria
Operaciones de set (en rangos ordenados)
Operaciones de pila
(C++11)
Operaciones minimo/maximo
(C++11)
(C++17)
Permutaciones
Operaciones numéricas
Bibliotecas C
 
Definido en la cabecera <algorithm>
template< class ForwardIt, class T >
void fill( ForwardIt first, ForwardIt last, const T& value );
Asigna el value dado a los elementos en el rango [first, last) .
Original:
Assigns the given value to the elements 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.

Contenido

[editar] Parámetros

first, last -
la gama de elementos a modificar
Original:
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.
value -
el valor a asignar
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.
Requerimientos de tipo
-
ForwardIt debe reunir los requerimientos de ForwardIterator.

[editar] Valor de retorno

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

[editar] Complejidad

Exactamente last - first tareas .
Original:
Exactly last - first assignments.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Posible implementación

template< class ForwardIt, class T >
void fill(ForwardIt first, ForwardIt last, const T& value)
{
    for (; first != last; ++first) {
        *first = value;
    }
}

[editar] Ejemplo

El código siguiente utiliza fill() para establecer todos los elementos de un vector de enteros a -1:
Original:
The following code uses fill() to set all of the elements of a vector of integers to -1:
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()
{
    int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
    std::vector<int> v1(data, data+10);
 
    std::fill(v1.begin(), v1.end(), -1);
 
    for (vector<int>::iterator it = v1.begin(); it != v1.end(); ++it) {
        std::cout << *it << " ";
    }
    std::cout << "\n";
}

Salida:

-1 -1 -1 -1 -1 -1 -1 -1 -1 -1

[editar] Ver también

asigna un valor a una serie de elementos
Original:
assigns a value to a number of elements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(plantilla de función) [editar]
guarda el resultado de una función en un intervalo
Original:
saves the result of a function in a range
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(plantilla de función) [editar]
se aplica una función a una serie de elementos
Original:
applies a function to a range of elements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(plantilla de función) [editar]