温馨提示×

c++输出最小值的方法是什么

c++
小亿
91
2024-06-06 16:48:20
栏目: 编程语言

在C++中,可以使用STL中的min_element函数来输出最小值。这个函数需要在#include <algorithm>头文件中使用。下面是一个示例代码:

#include <iostream>
#include <algorithm>
#include <vector>

int main() {
    std::vector<int> numbers = {4, 2, 7, 1, 9, 5};
    
    auto min_value = *std::min_element(numbers.begin(), numbers.end());
    
    std::cout << "The minimum value is: " << min_value << std::endl;

    return 0;
}

运行上面的代码,将会输出数组numbers中的最小值。

0