給出了在 C++ 中顯示 ratio_less_equal () 函數工作的任務。
給定的函數 Ratio_less_equal 檢查 ratio1 的值是否小於或等於 ratio2。它返回一個布爾常量 “value”,如果 ratio1 小於或等於 ratio2,則返回 true,否則返回 false。
用法
template ratio_less_equal
參數
該函數接受兩個模板參數,一個是 ratio1,另一個是 ratio2,要進行比較。
此函數的說明
在此函數中,如果 ratio1 的值小於或等於 ratio2 的值,則此函數將返回布爾值,該值為真,即整數位 1,否則將返回 false,即整數位 0。
例如
Input:1/3 and 3/9 Output:1/3 is less than or equal to 3/9. Input:1/4 and 1/4 Output:1/4 is equal to 1/4.
我們在以下程序中使用的方法
首先我們聲明這兩個比率。
然後分配兩個比率的值。
然後我們檢查 ratio1 的值是否小於或等於 ratio2 的值。
使用 ratio_less_equal 我們可以檢查
示例
// C++ code demonstrate the working of ratio_less_equal #include<iostream.h> #include<ratio.h> Using namespace std; Int main( ){ typedef ratio<1, 3> ratio1; typedef ratio<3, 9> ratio2; if(ratio_less_equal<ratio1, ratio2>::value) cout<< “ ratio1 is less than or equal to ratio2”; else cout<< “ ratio1 is not less than or equal to ratio2”; return 0; }
輸出
如果我們運行上麵的代碼,它將生成以下輸出。
1/3 is less than or equal to 3/9. 4/16 is not less than or equal to 1/4.
相關用法
- C++ Ratio_less()用法及代碼示例
- C++ Ratio_greater()用法及代碼示例
- C++ Ratio_greater_equal()用法及代碼示例
- C++ unordered_map cbegin用法及代碼示例
- C++ map lower_bound()用法及代碼示例
- C++ Unordered_multimap reserve()用法及代碼示例
- C++ list assign()用法及代碼示例
- C++ std::max()用法及代碼示例
- C++ std::string::push_back()用法及代碼示例
- C++ Array swap()用法及代碼示例
- C++ multimap key_comp()用法及代碼示例
- C++ Deque erase()用法及代碼示例
- C++ List cend()用法及代碼示例
- C++ std::less_equal用法及代碼示例
- C++ set rbegin()用法及代碼示例
- C++ llround()用法及代碼示例
- C++ getline(string)用法及代碼示例
- C++ boost::algorithm::all_of()用法及代碼示例
- C++ string::length()用法及代碼示例
- C++ Unordered_map end()用法及代碼示例
注:本文由純淨天空篩選整理自Sunidhi Bansal大神的英文原創作品 Ratio_less_equal function in C++。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。