ratio_less()是C++中的內置函數,可檢查比率R1是否小於比率R2。如果比率小於比率2,則返回True;否則返回false。
用法:
template ratio_less
模板參數:該函數接受兩個要比較的模板參數ratio1和ratio2。
返回值:該函數返回一個布爾值,如果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
相關用法
- C++ log()用法及代碼示例
- C++ div()用法及代碼示例
- C++ fma()用法及代碼示例
- C++ map key_comp()用法及代碼示例
- C++ wcsncpy()用法及代碼示例
- C++ imag()用法及代碼示例
- C++ real()用法及代碼示例
- C++ valarray end()用法及代碼示例
- C++ regex_iterator()用法及代碼示例
- C++ valarray cos()用法及代碼示例
注:本文由純淨天空篩選整理自Twinkl Bajaj大神的英文原創作品 ratio_less() function in C++。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。