Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
按相反顺序将一个向量复制到另一个向量 我是C++的新手。 我需要把一个向量按相反的顺序复制到另一个向量上_C++_Vector_Stl - Fatal编程技术网

按相反顺序将一个向量复制到另一个向量 我是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++]以相反顺序复制向量”可以找到)。这正是我所需要的。谢谢:)