How can I push_back data in a 2d vector of type int

前端 未结 6 869
借酒劲吻你
借酒劲吻你 2021-02-02 03:03

I have a vector and want to store int data in to it at run time can I store the data in a 2D vector in this manner ?

std::vector> n         


        
6条回答
  •  被撕碎了的回忆
    2021-02-02 03:28

    Yes, but you also need to push each of the sub-vectors:

    std::vector> normal;
    for(int i=0; i<10; i++)
    {
        normal.push_back(std::vector());
        for(int j=0; j<20; j++)
        {    
            normal[i].push_back(j);    
        }
    }
    

提交回复
热议问题