How can I initialize 2d array with a list of 1d arrays?

前端 未结 4 1802
孤街浪徒
孤街浪徒 2021-01-18 05:21

How can I initialize 2d array with a list of 1d arrays?

void main()
{
    int a[] = { 1,2,3 };
    int b[] = { 4,5,6 };
    int array[][3] = { a,b };
}
         


        
4条回答
  •  离开以前
    2021-01-18 05:29

    Use std::array.

    auto a = std::array{ 1,2,3 };
    auto b = std::array{ 4,5,6 };
    auto array = std::array{ a,b };
    

    Demo

提交回复
热议问题