Using generate to fill values to a vector : generate « STL Algorithms Modifying sequence operations « C++ Tutorial






#include <algorithm>
#include <vector>
#include <list>
#include <iostream>

int main (){
    using namespace std;

    vector <int> v (10);
    generate ( v.begin (), v.end () , rand );    

    cout << "Elements in the vector of size " << v.size ();
    for (size_t nCount = 0; nCount < v.size (); ++ nCount)
        cout << v [nCount] << " ";

    return 0;
}








24.3.generate
24.3.1.Provide predicate for std::generate
24.3.2.Illustrating the generic generate algorithm: Fill vector1 with 1, 4, 9, 16, ..., 100
24.3.3.Use std::generate to fill elements in a vector
24.3.4.Int sequence
24.3.5.Use generate to insert five random numbers into a list
24.3.6.Using generate to fill values to a vector