2D array values C++

后端 未结 5 417
鱼传尺愫
鱼传尺愫 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:20

    Like this:

    int main()
    {
        int arr[2][5] =
        {
            {1,8,12,20,25},
            {5,9,13,24,26}
        };
    }
    

    This should be covered by your C++ textbook: which one are you using?

    Anyway, better, consider using std::vector or some ready-made matrix class e.g. from Boost.

提交回复
热议问题