当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C++ ratio_not_equal()用法及代码示例


ratio_not_equal是C++ STL中的内置函数,用于检查两个给定的比率是否相等或相等。

用法:

template  ratio_not_equal

模板参数:该函数接受两个要比较的模板参数ratio1和ratio2。


返回值:如果比率不相等,则该函数返回true,否则返回false。

以下程序演示了该函数:

示例1:

// C++ program to illustrate the 
// ratio_not_equal function 
#include <iostream> 
#include <ratio> 
using namespace std; 
int main() 
{ 
    typedef ratio<3, 9> ratio1; 
    typedef ratio<1, 3> ratio2; 
  
    // If both the ratios are not same 
    if (ratio_not_equal<ratio1, ratio2>::value) 
        cout << "Both ratio are not equal"; 
    else
        cout << "Both ratio are equal"; 
  
    return 0; 
}
输出:
Both ratio are equal

示例2:

// C++ program to illustrate the 
// ratio_equal function 
#include <iostream> 
#include <ratio> 
using namespace std; 
int main() 
{ 
    typedef ratio<1, 2> ratio1; 
    typedef ratio<5, 4> ratio2; 
  
    // If both the ratios are not same 
    if (ratio_not_equal<ratio1, ratio2>::value) 
        cout << "Both ratio are not equal"; 
    else
        cout << "Both ratio are equal"; 
  
    return 0; 
}
输出:
Both ratio are not equal


相关用法


注:本文由纯净天空筛选整理自Twinkl Bajaj大神的英文原创作品 ratio_not_equal() in C++ with examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。