📜  C++中的ratio_equal()及其示例

📅  最后修改于: 2021-05-30 12:38:27             🧑  作者: Mango

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

句法:

template < class ratio1_name, class ratio2_name > ratio_equal

模板参数:该函数接受两个模板参数比1比*这些都是进行比较。

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

下面的程序说明了ratio_equal()函数:

程序1:

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

程式2:

// C++ program to illustrate the
// ratio_equal function
#include 
#include 
using namespace std;
int main()
{
    typedef ratio<1, 2> ratio1;
    typedef ratio<5, 4> ratio2;
  
    // If both the ratios are same
    if (ratio_equal::value)
        cout << "Both ratio are equal";
    else
        cout << "Both ratio are not equal";
  
    return 0;
}
输出:
Both ratio are not equal
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”