Assigns the given value to the elements in the range (vector) - Dieptranivsr/DroneIVSR GitHub Wiki

One way to do this is to manually provide a value to each position in the vector.

The fill function assigns the value val to all the elements in the range [begin, end), where begin is the initial position and end is the last position.

NOTE : Notice carefully that ‘begin’ is included in the range but end is NOT included. Below is an example to demonstrate fill :

// C++ program to demonstrate working of fill()
#include <bits/stdc++.h>
using namespace std;

int main ()
{
     vector<int> vect(8);

     // calling fill to initialize values in the
     // range to 4
     fill(vect.begin() + 2, vect.end() - 1, 4);

     for (int i=0; i<vect.size(); i++)
          cout << vect[I] << " ";

     return 0;
}

Output :

   0 0 4 4 4 4 4 0
⚠️ **GitHub.com Fallback** ⚠️