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

前端 未结 6 870
借酒劲吻你
借酒劲吻你 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:39

    You have a vector of vectors.

    normal[i] Does not exist because you have not created it.

    std::vector > normal:
    for(i=0;i<10;i++){
        normal.emplace_back();
        for(j=0;j<20;j++){
            normal.back().push_back(j);
        }
    }
    
    for(i=0;i<10;i++){
        for(j=0;j<20;j++){
            std::cout << normal[i][j] << " ";
        }
        std::cout << std::endl;
    }
    

提交回复
热议问题