How to define a 2D array in C++ and STL without memory manipulation?

后端 未结 8 1307
隐瞒了意图╮
隐瞒了意图╮ 2021-02-06 03:14

There are several ways to define a 2D array in C++ and STL without memory manipulation, and the following codes illustrate two different methods:

int main () 
{
         


        
8条回答
  •  暖寄归人
    2021-02-06 03:30

    you can something like this vector> m_2DArray;

    then once you know the number of rows (rows) and number of columns (columns), you can resize your 2d array

    m_2DArray.resize(rows);

    for(auto& el:m_2DArray) el.resize(columns);

    you can access data in the 2d array using m_2DArray[i][j], just like any other 2D array

提交回复
热议问题