

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to reverse a Vector using STL in C++?
In this tutorial, we will be discussing a program to understand how to reverse a vector using STL in C++.
For reversing a given vector we will be using the reverse() function from the STL library in C++.
Example
#include <bits/stdc++.h> using namespace std; int main(){ //collecting the vector vector<int> a = { 1, 45, 54, 71, 76, 12 }; cout << "Vector: "; for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << endl; //reversing the vector reverse(a.begin(), a.end()); cout << "Reversed Vector: "; for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << endl; return 0; }
Output
Vector: 1 45 54 71 76 12 Reversed Vector: 12 76 71 54 45 1
- Related Questions & Answers
- How to reverse a vector in R?
- How to reverse an Array using STL in C++?
- How to sort a Vector in descending order using STL in C++?
- How to find the maximum element of a Vector using STL in C++?
- Sorting a vector of custom objects using C++ STL
- How to find the sum of elements of a Vector using STL in C++?
- forward_list::reverse( ) in C++ STL
- vector::begin() and vector::end() in C++ STL
- C++ Program to Implement Vector in STL
- List reverse function in C++ STL
- All reverse permutations of an array using STL in C++?
- vector insert() function in C++ STL
- How to reverse a String using C#?
- Find and print duplicate words in std::vector using STL functions using C++.
- How to remove an item from a C++ STL vector with a certain value?
Advertisements