Difference between vector V[] and vector< vector> > V

前端 未结 5 1703
陌清茗
陌清茗 2020-12-28 17:06

vector V[] and vector< vector > V both are 2D array.

But what is the differenc

5条回答
  •  被撕碎了的回忆
    2020-12-28 17:41

    One difference would be that although both can be initialized in the same way, e.g.

    vector V1[]        {{1,2,3}, {4,5,6}};
    vector> V2  {{1,2,3}, {4,5,6}};
    

    and accessed

    cout << V1[0].back() << endl;
    cout << V2[0].back() << endl;
    

    the V1 can't grow. You cannot make V1.push_back(...) as its not a vector object. Its just an array. Second one is dynamic. You can grow it as you please.

提交回复
热议问题