Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::fill

 

std::fill is an STL algorithm to assign values to a container.

 

#include <algorithm>
#include <cassert>
#include <numeric>
#include <vector>

int main()
{
  //Create a std::vector storing '1' 10x
  std::vector<int> v(10,1);
  //10 x 1 = 10
  assert(std::accumulate(v.begin(),v.end(),0)==10);
  //Fill the std::vector with '2'
  std::fill(v.begin(),v.end(),2);
  //10 x 2 = 20
  assert(std::accumulate(v.begin(),v.end(),0)==20);
}


 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict