min_element
时间: 2023-09-10 11:07:17 浏览: 123
element-ui.min
The `min_element` function is a standard library algorithm in C++ that finds the smallest element in a range of elements. It takes two arguments - the beginning and end iterators of the range - and returns an iterator pointing to the smallest element.
Here's an example usage of `min_element` to find the smallest element in a vector of integers:
```c++
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
std::vector<int> nums = {5, 2, 8, 1, 9, 4};
auto min_it = std::min_element(nums.begin(), nums.end());
std::cout << "The smallest element is " << *min_it << "\n";
return 0;
}
```
This program will output: `The smallest element is 1`.
阅读全文