- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 find the maximum element of a Vector using STL in C++?
In this tutorial, we will be discussing a program to understand how to find the maximum element of a vector using STL in C++.
To find the maximum element from a given vector, we will be using the *max_element() method from STL library.
Example
#include <bits/stdc++.h> using namespace std; int main(){ //defining 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; //finding the maximum element cout << "Max Element = " << *max_element(a.begin(), a.end()); return 0; }
Output
Vector: 1 45 54 71 76 12 Max Element = 76
- Related Articles
- How to find the maximum element of an Array using STL in C++?
- How to find the minimum and maximum element of an Array using STL in C++?
- How to find the sum of elements of a Vector using STL in C++?
- How to reverse a Vector using STL in C++?
- Find the maximum element of a Vector in Java
- How to sort a Vector in descending order using STL in C++?
- Sorting a vector of custom objects using C++ STL
- Find and print duplicate words in std::vector using STL functions using C++.
- How to find the index of an element in a vector in R?
- C++ Program to Implement Vector in STL
- vector::begin() and vector::end() in C++ STL
- Find the minimum element of a Vector in Java
- How to find the index of the minimum and maximum value of a vector in R?
- Program to find the maximum element in a Matrix in C++
- vector insert() function in C++ STL

Advertisements