c++ 利用容器vector动态的定义二维数组
#include <iostream> #include <vector> using namespace std; int main() { int row, column; cin >> row >> column; //key code:申请空间 vector<vector<int> > a(row, vector<int>(column)); //使用空间 for (int j = 0; j < row; j++) for (int k = 0; k < column; k++) a[j][k] = rand() % 100; for (int j = 0; j < row; j++) { cout << endl; for (int k = 0; k < column; k++) { a[j][k] = rand() % 100; cout << a[j][k] << " "; } } return 0; }
posted on 2018-03-01 17:06 HelloShijam 阅读(2383) 评论(0) 编辑 收藏 举报