C++ boost库教程(十):boost 多维动态数组multi

    xiaoxiao2023-11-15  142

             C 在创建数组时必须制定除第一维外的维数,例如 :

    arr[m][n]; /* 表示m行n列,如果不指定第二个参数,就无法指定列数,例如 arr[3][a] = {1,2,3,4,5,6,7} 那么该二维数组的排列方式有多种,如果指定第二列 arr[][3], 那么只有一种排列结果: 1 2 3 4 5 6 7 */

            例如在VS中创建二维数组:

           boost支持这种多维动态数组multi_array,与C 中内建的多维数组一样的接口和行为,使用时需要包含头文件

    #include<boost/multi_array.hpp>

    示例代码如下:

    #include "stdafx.h" #include<iostream> using namespace std; #include<boost/array.hpp> #include<boost/multi_array.hpp> using namespace boost; int main() { int a = 2; int b = 3; int c = 4; //创建了一个 3维数组,每一维的长度可以动态指定,不需要编译时指定 multi_array<
    最新回复(0)