C++ 检查较低数字的条件
C++ Condition to check for lower number with a treshold
肯定
有更好的方法来做到这一点,C++这个?
if ( width_value < tipWidth )
{
if (tipWidth < threshold)
{
return threshold;
}
return tipWidth;
}
return width_value ;
return std::max(width_value, std::max(tipWidth, threshold))
或者从 C++11 开始:
return std::max({width_value, tipWidth, threshold})
这是假设你#include <algorithm>
,tipWidth
width_value
的类型threshold
是相同的。如果不相同,则必须明确指定,例如 std::max<int>(...)
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- 用C++中的数字和条件填充向量
- 实现基于数字值(正、负、零)的条件表达式的最佳方法
- 使用 if 条件对数字进行分组
- C :是否值得使用static_cast避免使用数字的条件
- 将数字划分为直到满足条件= 0
- 递归计算满足条件的值数并返回该数字
- 在C++有没有更好的方法可以做到这一点?检查哪些数字满足条件 [A*B*C = A! + B! + C!]
- 在有条件的向量中找到最接近的数字
- C++ 检查较低数字的条件
- 验证每个数字是否在特定条件下
- 为什么 for 循环没有达到循环的第二个条件中设置的数字
- placeNumbers应该返回数字的顺序,以便满足布尔值向量中编码的条件
- 缩短条件以检查x是否不是四个数字中的任何一个
- 如何在循环延续条件下区分数字 10 和 'n'?
- 根据特定的约束条件生成3位数字
- 条件操作者的最高 4 个数字
- 如果条件计算字符串中的 "1" 位数字未执行