![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
Advertisements