C++中的函数()

这个 比率_减去() 是C++中的内置函数,它检查比率R1是否小于比率R2。如果比率小于比率2,则返回True,否则返回false。

null

语法:

template < class ratio1_name, class ratio2_name > ratio_less

模板参数: 该函数接受两个模板参数 比率1 比率2 这些都是可以比较的。

返回值: 该函数返回一个布尔值,如果ratio1小于ratio2,则该值为true,否则返回false。

以下程序说明了上述功能:

项目1:

// C++ program to illustrate the
// ratio_less function
#include <iostream>
#include <ratio>
using namespace std;
int main()
{
typedef ratio<3, 9> ratio1;
typedef ratio<1, 3> ratio2;
// check if R1<R2
if (ratio_less<ratio1, ratio2>::value)
cout << "3/9 is less than 1/3" ;
else
cout << "3/9 is not less than 1/3" ;
return 0;
}


输出:

3/9 is not less than 1/3

项目2:

// C++ program to illustrate the
// ratio_less function
#include <iostream>
#include <ratio>
using namespace std;
int main()
{
typedef ratio<1, 2> ratio1;
typedef ratio<4, 7> ratio2;
// check if R1<R2
if (ratio_less<ratio1, ratio2>::value)
cout << "1/2 is less than 4/7" ;
else
cout << "1/2 is not less than 4/7" ;
return 0;
}


输出:

1/2 is less than 4/7

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享