There's a function std::reverse in the algorithm header for this purpose.

#include <vector>
#include <algorithm>

int main() {
  std::vector<int> a;
  std::reverse(a.begin(), a.end());
  return 0;
}
Answer from Ivaylo Strandjev on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › stdreverse-in-c
reverse() in C++ STL - GeeksforGeeks
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v = {1, 3, 6, 2, 9}; int n = v.size(); int d = 2; // Left rotate the vector by d place reverse(v.begin(), v.begin() + d); reverse(v.begin() + d, v.end()); reverse(v.begin(), v.end()); for (auto i : v) cout << i << " "; return 0; }
Published   January 20, 2026
Discussions

c++ please 20 LAB: Reverse vector plete Reverse() function that returns a new character vector containing all contents in the input argument reversed. f the input vector is: a', 'b', 'c'] n the returned vector will be: 'c', 'b', 'a'] 70.1771362.qx3zqy7 LAB ACTIVITY 4.20.1: LAB: Reverse vector 1 #include 2 #include 3 using namespace std; 4 5 // This method
Answer to c++ please 20 LAB: Reverse vector plete Reverse() More on chegg.com
🌐 chegg.com
1
July 2, 2023
Proper way to do backward iteration in C++
for (size_t i = data.size(); i--;) More on reddit.com
🌐 r/cpp
82
26
August 3, 2018
Reverse Iteration in C++ STL
I am getting error But it’s a secret error the first iteration of lowercase What? More on reddit.com
🌐 r/cpp_questions
6
2
December 13, 2023
Vectors-- reversing an array - C++ Forum
Hello, I am prompted to write a ... them in reverse order. I have written the code below thus far, which is a combination of two set of code I had written earlier that worked just, although I do understand their connection may be faulty. I am quite lost on how to move forward from this problem. The exact instructions are below: "Write a program that prompts the user for 10 integers and stores them in a vector... More on cplusplus.com
🌐 cplusplus.com
🌐
Cppreference
en.cppreference.com › w › cpp › algorithm › reverse.html
std::reverse - cppreference.com
February 9, 2025 - #include <algorithm> #include <iostream> #include <iterator> #include <vector> void println(auto rem, auto const& v) { for (std::cout << rem; auto e : v) std::cout << e << ' '; std::cout << '\n'; } int main() { std::vector<int> v {1, 2, 3}; std::reverse(v.begin(), v.end()); println("after reverse, v = ", v); int a[] = {4, 5, 6, 7}; std::reverse(std::begin(a), std::end(a)); println("after reverse, a = ", a); }
🌐
Cplusplus
cplusplus.com › reference › algorithm › reverse
std::reverse
Reverses the order of the elements in the range [first,last). The function calls iter_swap to swap the elements to their new locations.
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › how-to-reverse-a-vector-using-stl-in-c
How to Reverse a Vector using STL in C++? - GeeksforGeeks
July 11, 2025 - Explanation: The reverse() function reversed the order of all elements of the vector v. C++ also provides other methods to reverse a vector.
🌐
Northern Kentucky University
nku.edu › ~longa › Rweb › library › base › html › rev.html
R: Reverse a Vector's Elements
rev provides a reversed version of its argument. It can be used in combination with sort to obtain vectors sorted into descending order.
🌐
Edureka Community
edureka.co › home › community › categories › c++ › how do i reverse a c vector
How do I reverse a C vector | Edureka Community
June 27, 2022 - Is there a vector function in C++ that can reverse a vector in place? Or do you have to do it by hand?
Find elsewhere
🌐
DEV Community
dev.to › emilossola › reversing-a-vector-in-c-efficient-techniques-and-best-practices-436o
Reversing a Vector in C++: Efficient Techniques and Best Practices - DEV Community
July 17, 2023 - This can be achieved by using two pointers, one pointing to the first element and the other pointing to the last element, and incrementing the first pointer while decrementing the second pointer in each iteration.
🌐
Reddit
reddit.com › r/cpp › proper way to do backward iteration in c++
r/cpp on Reddit: Proper way to do backward iteration in C++
August 3, 2018 -

Suppose we have some vector<T> data, and wanna iterate it backwards maintaining the index. We all know the struggle, can't just write

for (size_t i = data.size() - 1; i >= 0; --i) 

So there are multiple ways to deal with it, all are equally bad. For a example

for (ssize_t i = static_cast<ssize_t>(data.size()) - 1; i >= 0; --i)

which doesn't work if data.size() > SSIZE_MAX.

Or there is something like

for (size_t rev_i = 0; rev_i < data.size(); ++rev_i) {
  size_t i = data.size() - rev_i - 1;
}

Do we really need two variables to perform such a complex action? Hopefully, there is a way. Just do

for (size_t i = data.size() - 1; i < data.size(); --i)

which works with any data.size() and more importantly shows your superior c++ coding skills. Also be ready to be praised by your colleagues for writing readable code.

🌐
Scaler
scaler.com › home › topics › how to reverse a vector in c++?
How to Reverse a Vector in C++? - Scaler Topics
September 27, 2023 - C++ offers a convenient way to achieve this using the std::reverse() function from the Standard Template Library (STL). This function streamlines the process, saving both time and effort.
🌐
Quora
quora.com › Whats-the-easiest-way-to-reverse-a-vector-in-C++
What's the easiest way to reverse a vector in C++? - Quora
Reverse a Vector in C++ Using Reverse IteratorsIn C++, reverse iterators are utilized with the methods rbegin() and rend(). These iterators traverse the vector in reverse, enabling us to modify items easily.
🌐
IncludeHelp
includehelp.com › stl › reverse-vector-elements.aspx
How to reverse vector elements in C++ STL?
To reverse vector elements, we can use reverse() function which is defined in <algorithm> header in C++ standard template library.
🌐
Cplusplus
cplusplus.com › reference › vector › vector › rbegin
std::vector::rbegin
Returns a reverse iterator pointing to the last element in the vector (i.e., its reverse beginning). Reverse iterators iterate backwards: increasing them moves them towards the beginning of the container. rbegin points to the element right before the one that would be pointed to by member end.
🌐
Shiksha
shiksha.com › home › it & software › programming › colleges in india
Best Programming Colleges in India - Courses, Fees, Admissions 2026, Placements
July 4, 2025 - Programming is the process of generating a set of commands to use artificial intelligence and computer systems for performing tasks.
🌐
Cplusplus
cplusplus.com › forum › beginner › 232236
Vectors-- reversing an array - C++ Forum
The final code is as follows: #include <iostream> #include <vector> using namespace std; int main() { const int INTEGERS = 10; vector<int> userArray(INTEGERS); int i; cout << "Enter " << INTEGERS << " integers: "; for (int i = 0; i < INTEGERS; i++) { cin >> userArray[i]; } for (int i = INTEGERS - 1; i >= 0; i--) { cout << userArray[i] << " "; } //system("pause"); return 0; }
🌐
Cprogramming
cboard.cprogramming.com › cplusplus-programming › 115989-reverse-member-function.html
reverse member function
May 17, 2009 - Gaddis (p. 451) has a reverse function for vectors that MS doesn't seem to recognize. Just experimenting around with his various vector member functions, I have the vector NumVect1 with 5 integer members (and I have the #include <vector> header), but when I put in the line of code: The reverse function that tabstop mentioned is actually a non-member function template.
🌐
Intellipaat
intellipaat.com › home › blog › how to reverse vector in c++: complete guide
How to Reverse a Vector in C++? - Intellipaat
November 29, 2024 - The reverse() function from the <algorithm> header reverses the elements in a given range. It takes two objects that allow you to traverse through the elements indicating the range (begin(), end()) of the vector.