c++ 容器元素填充指定数量的元素(generate_n)

 

#include <iostream>     // cout
#include <algorithm>    // generate_n
using namespace std;
int current = 0;
int UniqueNumber () { return ++current; }

int main () {
  int myarray[9];

  generate_n (myarray, 5, UniqueNumber);

  cout << "myarray contains:";
  for (int i=0; i<9; ++i)
    cout << ' ' << myarray[i];
  cout << '\n';

  return 0;
}

 

posted @ 2018-10-21 01:14  anobscureretreat  阅读(328)  评论(0编辑  收藏  举报