博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
stl max函数_std :: max()函数以及C ++ STL中的示例
阅读量:2530 次
发布时间:2019-05-11

本文共 1762 字,大约阅读时间需要 5 分钟。

stl max函数

C ++ STL std :: max()函数 (C++ STL std::max() function)

max() function is a library function of algorithm header, it is used to find the largest value from given two values, it accepts two values and returns the largest value and if both the values are the same it returns the first value.

max()函数算法标头的库函数,用于从给定的两个值中查找最大值,它接受两个值并返回最大值,如果两个值相同,则返回第一个值。

Note:To use max() function – include <algorithm> header or you can simple use <bits/stdc++.h> header file.

注意:要使用max()函数 –包括<algorithm>头文件,或者您可以简单地使用<bits / stdc ++。h>头文件。

Syntax of std::max() function

std :: max()函数的语法

std::max(const T& a, const T& b);

Parameter(s): const T& a, const T& b – values to be compared.

参数: const T&a,const T&b –要比较的值。

Return value: T – it returns the largest value of type T.

返回值: T –返回类型T的最大值。

Example:

例:

Input:    int a = 10;    int b = 20;        //finding largest value    cout << max(a,b) << endl;        Output:    20

C ++ STL程序演示std :: max()函数的使用 (C++ STL program to demonstrate use of std::max() function)

In this example, we are going to find the largest values from given values of different types.

在此示例中,我们将从不同类型的给定值中找到最大值。

#include 
#include
using namespace std;int main(){
cout << "max(10,20) : " << max(10, 20) << endl; cout << "max(10.23f,20.12f): " << max(10.23f, 20.12f) << endl; cout << "max(-10,-20) : " << max(-10, -20) << endl; cout << "max('A','a') : " << max('A', 'a') << endl; cout << "max('A','Z') : " << max('A', 'Z') << endl; cout << "max(10,10) : " << max(10, 10) << endl; return 0;}

Output

输出量

max(10,20)        : 20max(10.23f,20.12f): 20.12max(-10,-20)      : -10max('A','a')      : amax('A','Z')      : Zmax(10,10)        : 10

Reference:

参考:

翻译自:

stl max函数

转载地址:http://rgazd.baihongyu.com/

你可能感兴趣的文章
ZT:Linux上安装JDK,最准确
查看>>
LimeJS指南3
查看>>
关于C++ const成员的一些细节
查看>>
《代码大全》学习摘要(五)软件构建中的设计(下)
查看>>
C#检测驱动是否安装的问题
查看>>
web-4. 装饰页面的图像
查看>>
微信测试账户
查看>>
Android ListView上拉获取下一页
查看>>
算法练习题
查看>>
学习使用Django一 安装虚拟环境
查看>>
Hibernate视频学习笔记(8)Lazy策略
查看>>
CSS3 结构性伪类选择器(1)
查看>>
IOS 杂笔-14(被人遗忘的owner)
查看>>
自动测试用工具
查看>>
前端基础之BOM和DOM
查看>>
[T-ARA/筷子兄弟][Little Apple]
查看>>
编译Libgdiplus遇到的问题
查看>>
【NOIP 模拟赛】Evensgn 剪树枝 树形dp
查看>>
java学习笔记④MySql数据库--01/02 database table 数据的增删改
查看>>
两台电脑如何实现共享文件
查看>>