2D array values C++

后端 未结 5 416
鱼传尺愫
鱼传尺愫 2020-12-05 09:34

I wanted to declare a 2D array and assign values to it, without running a for loop.

I thought I could used the following idea

int array[5] = {1,2,3,         


        
5条回答
  •  醉梦人生
    2020-12-05 10:16

    One alternative is to represent your 2D array as a 1D array. This can make element-wise operations more efficient. You should probably wrap it in a class that would also contain width and height.

    Another alternative is to represent a 2D array as an std::vector >. This will let you use STL's algorithms for array arithmetic, and the vector will also take care of memory management for you.

提交回复
热议问题