What is the purpose of std::max in C++?
std::max is a function template in the C++ standard library that is used to return the larger of two values.
This function template has multiple overloaded versions that can be used to compare values of different types. It takes two parameters and returns the larger of the two values.
You need to include the header file when using std::max.
Example usage:
#include <iostream>
#include <algorithm>
int main() {
int a = 10;
int b = 20;
int result = std::max(a, b);
std::cout << result << std::endl; // 输出20
return 0;
}
In the example mentioned above, the std::max function takes two integers, a and b, as parameters and returns the larger value of the two, which is 20.