Generating a sequence in vector
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
double f() // A simple generator function.
{
static double val = 1.0;
double t;
t = 1.0 / val;
val += val;
return t;
}
int main()
{
vector<double> vectorObject(5);
int i;
generate(vectorObject.begin(), vectorObject.end(), f); // generate a series
cout << "Series: ";
for(i = 0; i <vectorObject.size(); i++)
cout << vectorObject[ i ] << " ";
return 0;
}
Related examples in the same category