#include<iostream> using namespace std; int main() { //设想要创建一个rows行,cols列的矩阵 //使用new进行新建 int rows, cols; cin >> rows >> cols; int **Array = new int*[rows]; //开辟行 //new for (int i = 0; i < rows; i++) Array[i] = new int[cols]; //开辟列 for(int i = 0; i < rows; i++) for(int j = 0; j < cols; j++) cin >> Array[i][j]; for(int i = 0; i < rows; i++) { for(int j = 0;j < cols ; j++) cout << Array[i][j]; cout << endl; } //delete for(int i = 0; i < rows; i++) delete [] Array[i]; delete []Array; return 0; }
对于其它类型的也能够写成相似的形式,很方便。ios
参考博客:https://blog.csdn.net/u012027907/article/details/16370625spa