función
C ++ STL variedad :: relleno () con el Ejemplo: Aquí, vamos a aprender sobre la relleno () la función de contenedor de matriz en C ++ Biblioteca de plantillas estándar (STL ) .
de llenado () es una función miembro de “array contenedor” , que establece un valor dado a todos los elementos de la matriz. También se puede utilizar para establecer el valor a otro de los contenedores también. Tipo de valor debe ser igual que el tipo de contenedores.
class ejemplo – si una matriz es un tipo entero entonces valor proporcionado debe ser un tipo entero. Si te facilitamos otro tipo de valor de relleno, se aplicará el tipo implícito fundido.
Sintaxis:
arr_name.fill(value);
Programa:
#include <iostream>
#include <array>
using namespace std;
int main()
{
//declaring array with dynamic size
array<int,5> arr;
//print array elements with default values
cout<<"Array elements with default values:n";
for (auto loop = arr.begin() ; loop != arr.end() ; ++loop)
cout<<*loop<<" ";
cout<<"n";
//fill array element with 0
arr.fill (0);
//AGAIN...
//print array element with default values
cout<<"Array elements after filling with 0:n";
for (auto loop = arr.begin() ; loop != arr.end() ; ++loop)
cout<<*loop<<" ";
cout<<"n";
//fill array element with 0
arr.fill (36);
//AGAIN...
//print array element with default values
cout<<"Array elements after filling with 36:n";
for (auto loop = arr.begin() ; loop != arr.end() ; ++loop)
cout<<*loop<<" ";
cout<<"n";
return 0;
}
salida
Array elements with default values:
142 0 0 0 994036560
Array elements after filling with 0:
0 0 0 0 0
Array elements after filling with 36:
36 36 36 36 36
Referencia: C ++ std :: array :: relleno ()