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

前端 未结 5 1718
陌清茗
陌清茗 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:47

    vector> v(26); is a vector containing vectors. In this example, you have a vector with 26 vectors contained in it. The code v[1].push_back(x) means that x is pushed back to the first vector within the vectors.

    vector a[26]; is an array of vectors. In other words, a one-dimensional array containing 26 vectors of integers. The code a[1].push_back(x); has x being pushed back to the first index of the array.

提交回复
热议问题