• 读取文件中数据,并赋值给二维数组


    void main()
    {
     int row, col;
     cout << "Please enter the number for row and column: " << endl;
     cin >> row >>col;

     //为二维数组开辟空间
     int **Result = new int*[row];
     for (int i = 0;  i < row;  i++)
     {
      Result[i] = new int[col];
     }

     ifstream fin("./data.txt");
     for (int i = 0; i != row; ++i) {
      for (int j = 0; j != col; ++j) {
       fin >> Result[i][j];
      }
     }
     fin.close();

     for (int w=0;w<row;w++)
     {
      for (int r=0;r<col;r++)
      {
       if(r<=w)
        cout<<0<<",";
       else
        cout<<Result[w][r]<<",";
      }
      cout<<endl;
     }

     //释放二维数组占用的空间
     for (int m = 0; m < row; m++)
     {
      delete[] Result[m];
     }
     delete[] Result;
     Result = NULL;
     //system("pause");
     return;
    }

  • 相关阅读:
    mysql读写分离
    mysql主从同步
    扫描与抓包
    加密与入侵检查
    监控
    selinux
    预期交互
    python发送邮件
    linux下安装虚拟环境
    博弈论
  • 原文地址:https://www.cnblogs.com/cumtb3S/p/2229078.html
Copyright © 2020-2023  润新知