stl min函数_std :: min()函数以及C ++ STL中的示例
stl min函數(shù)
C ++ STL std :: min()函數(shù) (C++ STL std::min() function)
min() function is a library function of algorithm header, it is used to find the smallest value from given two values, it accepts two values and returns the smallest value and if both the values are the same it returns the first value.
min()函數(shù)是算法標(biāo)頭的庫函數(shù),用于從給定的兩個(gè)值中查找最小值,它接受兩個(gè)值并返回最小值,如果兩個(gè)值相同,則返回第一個(gè)值。
Note:To use min() function – include <algorithm> header or you can simple use <bits/stdc++.h> header file.
注意:要使用min()函數(shù) –包括<algorithm>頭文件,或者您可以簡單地使用<bits / stdc ++。h>頭文件。
Syntax of std::min() function
std :: min()函數(shù)的語法
std::min(const T& a, const T& b);Parameter(s): const T& a, const T& b – values to be compared.
參數(shù): const T&a,const T&b –要比較的值。
Return value: T – it returns the smallest value of type T.
返回值: T –返回類型T的最小值。
Example:
例:
Input:int a = 10;int b = 20;//finding smallest valuecout << min(a,b) << endl;Output:10C ++ STL程序演示了std :: min()函數(shù)的使用 (C++ STL program to demonstrate use of std::min() function)
In this example, we are going to find the smallest values from given values of different types.
在此示例中,我們將從不同類型的給定值中找到最小值。
#include <iostream> #include <algorithm> using namespace std;int main() {cout << "min(10,20) : " << min(10, 20) << endl;cout << "min(10.23f,20.12f): " << min(10.23f, 20.12f) << endl;cout << "min(-10,-20) : " << min(-10, -20) << endl;cout << "min('A','a') : " << min('A', 'a') << endl;cout << "min('A','Z') : " << min('A', 'Z') << endl;cout << "min(10,10) : " << min(10, 10) << endl;return 0; }Output
輸出量
min(10,20) : 10 min(10.23f,20.12f): 10.23 min(-10,-20) : -20 min('A','a') : A min('A','Z') : A min(10,10) : 10Reference: C++ std::min()
參考: C ++ std :: min()
翻譯自: https://www.includehelp.com/stl/std-min-function-with-example.aspx
stl min函數(shù)
總結(jié)
以上是生活随笔為你收集整理的stl min函数_std :: min()函数以及C ++ STL中的示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: keil lic_LIC的完整形式是什么
- 下一篇: md5不是对称密码算法_密码学中的消息摘