Or login with:
#include <algorithm> template < class ForwardIterator, class Generator > void generate( ForwardIterator first, ForwardIterator last, Generator gen );Parameters:
| Parameter | Description |
|---|---|
| first | A forward iterator addressing the position of the first element in the range to which values are to be assigned |
| last | A forward iterator addressing the position one past the final element in the range to which values are to be assigned |
| gen | A function object that is called with no arguments that is used to generate the values to be assigned to each of the elements in the range |
#include <iostream> #include <algorithm> #include <vector> #include <cstdlib> using namespace std; int main() { vector<int> v(10); cout <<"\nHere are the initial contents of v:\n"; for (vector<int>::size_type i=0; i<v.size(); i++) cout <<v.at(i)<<" "; cout <<"\nNow we fill v with randomly generated integer values."; generate(v.begin(), v.end(), rand); cout <<"\nHere are the revised contents of v:\n"; for (vector<int>::size_type i=0; i<v.size(); i++) cout <<v.at(i)<<" "; cout <<"\nFinally, we fill the last half of v with new randomly generated integer values."; generate(v.begin()+5, v.end(), rand); cout <<"\nHere are the revised contents of v:\n"; for (vector<int>::size_type i=0; i<v.size(); i++) cout <<v.at(i)<<" "; return 0; }
You must login to leave a messge