c++ 数组赋值
// generate_n example #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, 9, UniqueNumber); cout << "myarray contains:"; for (int i=0; i<9; ++i) cout << ' ' << myarray[i]; cout << '\n'; return 0; }
输出
myarray contains: 1 2 3 4 5 6 7 8 9