Q:

how to initialize a 2D vector C++

I'm a beginner in C++. 
I'm trying to make a Matrix class by my own to train me.
I declared in my class Matrix std::vector<std::vector<long>> m_data; whitch is a 2D vector to store my numbers. In a constructor I want to initialize my 2D array with 2 arguments : NbRows and NbCols. I'm stuck there.
Matrix::Matrix(unsigned int nb_row, unsigned int nb_col) 

{
    int i, j;
    m_nbRow = nb_row;
    m_nbCol = nb_col;

    for(i = 0; i < m_nbCol; i ++)
    {
        for(j = 0; j <m_nbRow; j ++)
        {
            // ?????
        }
    }
}

A:

A simple one-line solution is as follows:
Matrix(unsigned int nb_row, unsigned int nb_col){
    m_data = std::vector<std::vector<long>>(nb_row, std::vector<long>(nb_col,0));
}

You can replace the "0" with any other number, depending on what you wish to initialise your matrix to.

A:

You have to resize the outer vector before the first for loop.
The inner vector can be resized and then assigned to, or items pushed back to it.
Matrix::Matrix(unsigned int nb_row, unsigned int nb_col) 
{
    int i, j;
    m_nbRow = nb_row;
    m_nbCol = nb_col;

    m_data.resize(m_nbCol);
    for(i = 0; i < m_nbCol; i ++)
    {
        for(j = 0; j <m_nbRow; j ++)
        {
            m_data[i].push_back(<some value>);
        }
    }
}

or
Matrix::Matrix(unsigned int nb_row, unsigned int nb_col) 
{
    int i, j;
    m_nbRow = nb_row;
    m_nbCol = nb_col;

    m_data.resize(m_nbCol);
    for(i = 0; i < m_nbCol; i ++)
    {
        m_data[i].resize(m_nbRow);
        for(j = 0; j <m_nbRow; j ++)
        {
            m_data[i][j] = <some value>;
        }
    }
}

If you want to initialize the elements of the matrix to zero, you can simplify it to:
Matrix::Matrix(unsigned int nb_row, unsigned int nb_col) 
{
    m_nbRow = nb_row;
    m_nbCol = nb_col;
    m_data.resize(m_nbCol, std::vector<long>(m_nbRow));
}

PS
Normally, the first index of matrix corresponds to a row while the second index corresponds to a column. You are using them the other way around in your post. I assume you have a reason for that.

