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; }