operator> (<utility>)

测试,如果运算符左侧的对象包含对大于右侧对象。

template<Class Type> 
   bool operator>( 
      const Type& _Left, 
      const Type& _Right 
   ); 
template<class Type1, class Type2> 
   bool operator>( 
      const pair<Type1, Type2>& _Left,
      const pair<Type1, Type2>& _Right 
   );

参数

  • _Left
    运算符左侧的 pair 类型的对象。

  • _Right
    类型与运算符右侧的 pair 对象。

返回值

true,如果运算符左侧的 pair 比与运算符右侧的 pair 强大于;为 false

备注

_Left pair 对象比 _Right 对象强pair 被视为 _Left 值是否大于并不等于 _Right.

在对两对值的比较,第一个元素具有最高优先级。 如果协定类型不同,作为对的比较,则它们的比较结果的操作。 如果第一个元素的值不是不同的,则第二个元素的值比较作为对的比较,并且,它们的比较结果的操作。

示例

// utility_op_gt.cpp
// compile with: /EHsc
#include <utility>
#include <iomanip>
#include <iostream>

int main( )
{
   using namespace std;
   pair <int, double> p1, p2, p3, p4;

   p1 = make_pair ( 10, 2.22e-1 );
   p2 = make_pair ( 100, 1.11e-1 );
   p3 = make_pair ( 10, 1.11e-1 );
   p4 = make_pair ( 10, 2.22e-1 );

   cout.precision ( 3 );
   cout << "The pair p1 is: ( " << p1.first << ", " 
        << p1.second << " )." << endl;
   cout << "The pair p2 is: ( " << p2.first << ", " 
        << p2.second << " )." << endl;
   cout << "The pair p3 is: ( " << p3.first << ", " 
        << p3.second << " )." << endl;
   cout << "The pair p4 is: ( " << p4.first << ", " 
        << p4.second << " )." << endl << endl;

   if ( p1 > p2 )
      cout << "The pair p1 is greater than the pair p2." << endl;
   else
      cout << "The pair p1 is not greater than the pair p2." << endl;

   if ( p1 > p3 )
      cout << "The pair p1 is greater than the pair p3." << endl;
   else
      cout << "The pair p1 is not greater than the pair p3." << endl;

   if ( p1 > p4 )
      cout << "The pair p1 is greater than the pair p4." << endl;
   else
      cout << "The pair p1 is not greater than the pair p4." << endl;
}
  

要求

页眉: <实用工具>

命名空间: std