如何复制由向量组成的数组

How to copy a array consisting of vectors

我有这个向量数组,向量对: vector<pair<int, int> > adj[V];

如何将其复制到另一个变量?

vector<pair<int, int> > adjCopy[V] = adj; //not working;

我也试过使用 std:copy 但显示矢量(可变大小)在数组内部,因此无法复制。

vector<pair<int, int> > adjCopy[V];
std::copy_n(&adj[0], V, &adjCopy[0]); // or std::copy(&adj[0], &adj[0] + V, &adjCopy[0]);

更地道:

vector<pair<int, int> > adjCopy[V];
std::copy_n(begin(adj), V, begin(adjCopy)); // or std::copy(begin(adj), end(adj), begin(adjCopy));

一般不使用C数组,使用std::array,

std::array<std::vector<std::pair<int, int> >, V> adj;
auto adjCopy = adj;