按相反顺序将一个向量复制到另一个向量 我是C++的新手。 我需要把一个向量按相反的顺序复制到另一个向量上
我是这样做的:按相反顺序将一个向量复制到另一个向量 我是C++的新手。 我需要把一个向量按相反的顺序复制到另一个向量上,c++,vector,stl,C++,Vector,Stl,我是这样做的: int temp[] = {3, 12, 17}; vector<int>v(temp, temp+3); vector<int>n_v; n_v=v; reverse(n_v.begin(), n_v.end()); //Reversing new vector inttemp[]={3,12,17}; 矢量(温度,温度+3); 向量; n_v=v; 反向(n_v.begin(),n_v.end())//反转新向量 有没有简单的方法可以将STL
int temp[] = {3, 12, 17};
vector<int>v(temp, temp+3);
vector<int>n_v;
n_v=v;
reverse(n_v.begin(), n_v.end()); //Reversing new vector
inttemp[]={3,12,17};
矢量(温度,温度+3);
向量;
n_v=v;
反向(n_v.begin(),n_v.end())//反转新向量
有没有简单的方法可以将STL中的一个向量按相反顺序复制到另一个向量?只需执行以下操作:
vector<int>n_v (v.rbegin(), v.rend());
vectorr_v(v.rbegin(),v.rend());
您可以使用反向迭代器
:
std::vector<int> n_v(v.rbegin(), v.rend());
向量n_v(v.rbegin(),v.rend());
涵盖了这个主题的大部分变体(通过搜索此站点的“[c++]以相反顺序复制向量”可以找到)。这正是我所需要的。谢谢:)