• 转:用STL中的vector动态开辟二维数组


    用STL中的vector动态开辟二维数组


    源代码:
    #include <iostream>
    #include <vector>
    using namespace std;
    int main()
    {
     int m, //行数
         n; //列数
     cout << "input value for m,n:";
     cin>>m>>n;
     
     //注意下面这一行:vector<int后两个">"之间要有空格!否则会被认为是重载">>"。
     vector<vector<int> > vecInt(m, vector<int>(n)); 
     for (int i = 0; i < m; i++)    //初始化二维数组,,其实这里可以不用初始化的,vector中默认初始化为0
       for (int j = 0; j < n; j++)
          vecInt[i][j] = 0;
      
     for (i = 0; i < m; i++)         //输出二维数组vecInt[][]
     {
      for (j = 0; j < n; j++)
       cout<<vecInt[i][j]<<" ";
      cout<<endl;
     }
     return 0;
    }

  • 相关阅读:
    滚动条滚动方向
    阶乘函数-尾递归
    返回顶部
    CommonJS
    vuessr
    随机字符串
    indexedDB
    深层次选择器
    Vue3.0简单替代Vuex
    shell 学习笔记
  • 原文地址:https://www.cnblogs.com/acbingo/p/4556466.html
Copyright © 2020-2023  润新知