Espacios de nombres
Variantes
Acciones

std::fill_n

De cppreference.com
< cpp‎ | algorithm

 
 
Algoritmo biblioteca
Funciones
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Para no modificar la secuencia de las operaciones
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.
Modificación de la secuencia de operaciones
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.
Particionamiento operaciones
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.
Clasificación de las operaciones (en rangos ordenados)
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.
Las operaciones binarias de búsqueda (en rangos ordenados)
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.
Conjunto de operaciones (en rangos ordenados)
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.
Operaciones del montón
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.
Mínimo / máximo de operaciones
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.
Operaciones numéricas
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.
C biblioteca
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.
 
Defined in header <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 );
(hasta C++11)

(desde C++11)
Asigna el value valor dado a los elementos count primeros principios gama de first si count>0. No hace nada por lo demás .
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.

Contenido

[editar] Parámetros

first -
el comienzo de la gama de elementos a modificar
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 -
número de elementos a modificar
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 -
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.
Type requirements
-
OutputIt must meet the requirements of OutputIterator.

[editar] Valor de retorno

(Ninguno) (hasta C++11)
Original:
(none) (hasta 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 un más allá del último elemento asignado si count>0, first lo contrario. (desde C++11)
Original:
Iterator one past the last element assigned if count>0, first otherwise. (desde C++11)
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 count tareas, para 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.

[editar] Posible implementación

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;
}

[editar] Ejemplo

El código siguiente utiliza para asignar fill_n() -1 para la primera mitad de un vector de enteros:
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";
}

Output:

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

[editar] Ver también

asigna una serie de elementos de un cierto valor
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.

(función de plantilla) [edit]