I'm making a program that uses the std::generate_n
function. I can get it to work fine with arrays, but I can't figure out how to make it work with a list container. Here is what I have:
#include <iostream>
#include <algorithm>
#include <list>
using namespace std;
int current = 0;
int UniqueNumber () { return ++current; }
int main ()
{
list<int> L;
list<int>::iterator it;
generate_n (L.begin(), 9, UniqueNumber);
cout << "list contains:";
for (it=L.begin(); it!=L.end(); ++it)
cout << ' ' << *it << '\n';
return 0;
}
The output only displays "list contains:" with nothing after that. I know my output loop functions correctly because I tried it manually with the insert() method, so the problem is something with the generate_n function. I think I'm passing the arguments wrong. Anyone know what I did?