我有一个向量数组,成对的向量:vector<pair<int, int> > adj[V];
如何将此复制到另一个变量?
vector<pair<int, int> > adjCopy[V] = adj; //not working;
我也尝试使用std:copy
,但是显示向量(可变大小)在数组中,所以不能复制。
发布于 2021-05-12 21:51:33
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;
https://stackoverflow.com/questions/67514441
复制相似问题