min_element
时间: 2023-09-10 19:07:14 浏览: 35
The `min_element` function is a standard library algorithm in C++ that returns an iterator pointing to the smallest element in a range of elements. It takes two arguments: a starting iterator and an ending iterator that define the range of elements to search through.
Here is an example usage of the `min_element` function:
```
#include <iostream>
#include <algorithm>
#include <vector>
int main() {
std::vector<int> vec {5, 2, 9, 1, 7};
auto min_it = std::min_element(vec.begin(), vec.end());
std::cout << "The minimum element is: " << *min_it << std::endl;
return 0;
}
```
In this example, we create a vector of integers and use the `min_element` function to find the smallest element in that vector. The `min_it` variable is an iterator that points to the minimum element, which we then dereference and print to the console. The output of this program would be:
```
The minimum element is: 1
```