std :: reverse_copy in C++ STL Last Updated : 11 Jun, 2018 Summarize Comments Improve 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 Comment More infoAdvertise with us Next Article std::rotate vs std::rotate_copy in C++ STL P prateek sharma 7 Follow Improve Article Tags : C++ STL cpp-vector Practice Tags : CPPSTL Similar Reads reverse() in C++ STL In C++, the reverse() is a built-in function used to reverse the order of elements in the given range of elements. This range can be any STL container or an array. In this article, we will learn about reverse() function in C++.Letâs take a look at an example:C++#include <bits/stdc++.h> using n 3 min read std::rotate vs std::rotate_copy in C++ STL rotate in STL:It rotates the order of the elements in the range [first, last), in such a way that the element pointed by middle becomes the new first element, i, e, to the left. CPP // Illustrating the use of rotate algorithm #include <bits/stdc++.h> using namespace std; // Driver Program int 2 min read list reverse function in C++ STL The list::reverse() is a built-in function in C++ STL which is used to reverse a list container. It reverses the order of elements in the list container. Syntax: list_name.reverse()Parameters: This function does not accept any parameters. Return Value: This function does not return any value. It jus 1 min read forward_list::reverse() in C++ STL std::forward_list::reverse() is an inbuilt function in CPP STL which reverses the order of the elements present in the forward_list. Syntax: forwardlist_name.reverse()Parameter: The function does not accept any parameter. Return value: The function has no return value. It reverses the forward list. 1 min read C++ STL - Vector in Reverse Order Prerequisite: Vectors in C++ A vector can be printed in reverse order with the following methods: By traversing in the backward direction using indexingBy traversing in the backward direction using begin() and end() functions in C++ STLBy traversing in the backward direction using rbegin() and rend( 3 min read copy_n() Function in C++ STL Copy_n() is the C++ function defined in <algorithm> library in STL. It helps to copy one array element to the new array. Copy_n function allows the freedom to choose how many elements must be copied in the destination container. This function takes 3 arguments, the source array name, the size 2 min read Like