voidprint(vector<vector<int>> v){ int m = v.size(); int n = v[0].size(); cout << "print vector<" << m << ", " << n << ">" << endl; for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) cout << v[i][j] << "\t "; cout << endl; } }
intmain(){ //1.初始化方案1 vector<vector<int>> v1; v1.resize(10, vector<int>(10)); print(v1); for (int i = 0; i < 10; ++i) for (int j = 1; j <= 10; ++j) v1[i][j - 1] = i * 10 + j; print(v1);
//2.初始化方案2 vector<vector<int>> v2; v2.resize(10); for (int i = 0; i < 10; ++i) for (int j = 1; j <= 10; ++j) v2[i].push_back(i * 10 + j); print(v2);