이 튜토리얼에서는 C++에서 STL을 사용하여 벡터의 최대 요소를 찾는 방법을 이해하는 프로그램에 대해 설명합니다.
주어진 벡터에서 최대 요소를 찾기 위해 STL 라이브러리의 *max_element() 메서드를 사용할 것입니다.
예
#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;
} 출력
Vector: 1 45 54 71 76 12 Max Element = 76