共用方式為


operator== (<utility>)

測試,如果在運算子左方的物件與相等右邊物件。

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

參數

  • _Left
    型別 **pair.**物件

  • _Right
    型別 pair 的物件。

傳回值

true ,如果對相等; false ,如果 pair不等於。

備註

如果其每一個別項目相等,則為與另一個為相等。 函式會傳回 _Left。first == _Right。first &&_Left。second == _Right。second。 如果第一個或第二個項目的一個不等於其他對,對應的項目都是不相等。

範例

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

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

   p1 = make_pair ( 10, 1.11e-1 );
   p2 = make_pair ( 1000, 1.11e-3 );
   p3 = make_pair ( 10, 1.11e-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 << endl;

   if ( p1 == p2 )
      cout << "The pairs p1 and p2 are equal." << endl;
   else
      cout << "The pairs p1 and p2 are not equal." << endl;

   if ( p1 == p3 )
      cout << "The pairs p1 and p3 are equal." << endl;
   else
      cout << "The pairs p1 and p3 are not equal." << endl;
}

Output

The pair p1 is: ( 10, 0.111 ).
The pair p2 is: ( 1000, 0.00111 ).
The pair p3 is: ( 10, 0.111 ).

The pairs p1 and p2 are not equal.
The pairs p1 and p3 are equal.

需求

標題: <公用程式>

命名空間: std