VOOZH about

URL: https://www.geeksforgeeks.org/cpp/stdgenerate-in-c/

⇱ std::generate in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

std::generate in C++

Last Updated : 21 Jul, 2017
std::generate, as the name suggests is an STL algorithm, which is used to generate numbers based upon a generator function, and then, it assigns those values to the elements in the container in the range [first, last). The generator function has to be defined by the user, and it is called successively for assigning the numbers. Template function:
void generate (ForwardIterator first, ForwardIterator last, Generator gen);

first: Forward iterator pointing to the first element of the container.
last: Forward iterator pointing to the last element of the container.
gen: A generator function, based upon which values will be assigned.

Returns: none
Since, it has a void return type, so it does not return any value.
Output:
1 2 3 4 5 6 7 8 9 10
Next: std::generate_n in C++
Comment
Article Tags: