max()は最大値を返します。
書式は次の通りです。
template const T& max(const T& x, const T& y);
template const T& max(const T& x, const T& y, pred pr);
template T max(const valarray& x);
static T numeric_limits::max() throw();
T valarray::max() const;
次の例は、それぞれ2個の整数と文字列の最大値を出力するプログラムの例です。
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
int v1=12, v2=30;
cout << max(v1, v2) << endl;
string s1="ABC", s2="xyz";
string s3 = max(s1, s2);
cout << s3 << endl;
return 0;
}
実行結果は次の通りです。
30
xyz