std :: reverse_copy in C++ STL Last Updated : 11 Jun, 2018 Suggest changes Share Like Article Like Report C++ STL provides a function that copies the elements from the given range but in reverse order. Below is a simple program to show the working of reverse_copy(). Examples: Input : 1 2 3 4 5 6 7 8 9 10 Output : The vector is: 10 9 8 7 6 5 4 3 2 1 The function takes three parameters. The first two are the range of the elements which are to be copied and the third parameter is the starting point from where the elements are to be copied in reverse order. CPP // C++ program to copy from array to vector // using reverse_copy() in STL. #include <bits/stdc++.h> using namespace std; int main() { int src[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int n = sizeof(src) / sizeof(src[0]); vector<int> dest(n); reverse_copy(src, src + n, dest.begin()); cout << "The vector is: \n"; for (int x : dest) { cout << x << " "; } return 0; } Output: The vector is: 10 9 8 7 6 5 4 3 2 1 Below is an example of vector to vector copy. CPP // C++ program to copy from array to vector // using reverse_copy() in STL. #include <bits/stdc++.h> using namespace std; int main() { vector<int> src { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; vector<int> dest(src.size()); reverse_copy(src.begin(), src.end(), dest.begin()); cout << "The vector is: \n"; for (int x : dest) { cout << x << " "; } return 0; } Output: The vector is: 10 9 8 7 6 5 4 3 2 1 P prateek sharma 7 Follow Article Tags : C++ STL cpp-vector Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++4 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling through C++ Classes8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++4 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL3 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read My Profile ${profileImgHtml} My Profile Edit Profile My Courses Join Community Transactions Logout Like