共用方式為


<set> 運算子

operator!= (set)

測試運算子左邊的 set 物件是否不等於右邊的 set 物件。

bool operator!=(const set <Key, Traits, Allocator>& left, const set <Key, Traits, Allocator>& right);

參數

left
set 類型的物件。

right
set 類型的物件。

傳回值

true 如果集合不相等則為 ; false 如果集合相等,則為 。

備註

set 物件之間的比較是以其項目之間的成對比較為基礎。 如果兩個 set 具有相同的項目數,且其個別項目的值相同,則它們會相等。 反之則為不相等。

範例

// set_op_ne.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   set <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i );
   }

   if ( s1 != s2 )
      cout << "The sets s1 and s2 are not equal." << endl;
   else
      cout << "The sets s1 and s2 are equal." << endl;

   if ( s1 != s3 )
      cout << "The sets s1 and s3 are not equal." << endl;
   else
      cout << "The sets s1 and s3 are equal." << endl;
}
/* Output:
The sets s1 and s2 are not equal.
The sets s1 and s3 are equal.
*/

operator< (set)

測試運算子左邊的 set 物件是否小於右邊的 set 物件。

bool operator<(const set <Key, Traits, Allocator>& left, const set <Key, Traits, Allocator>& right);

參數

left
set 類型的物件。

right
set 類型的物件。

傳回值

true 如果運算子左邊的集合嚴格小於運算子右邊的集合,則為 ;否則 false為 。

備註

set 物件之間的比較是以其項目的成對比較為基礎。 兩個物件之間的小於關聯性是根據第一對不相等元素的比較。

範例

// set_op_lt.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   set <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
   }

   if ( s1 < s2 )
      cout << "The set s1 is less than the set s2." << endl;
   else
      cout << "The set s1 is not less than the set s2." << endl;

   if ( s1 < s3 )
      cout << "The set s1 is less than the set s3." << endl;
   else
      cout << "The set s1 is not less than the set s3." << endl;
}
/* Output:
The set s1 is less than the set s2.
The set s1 is not less than the set s3.
*/

operator<= (set)

測試運算子左邊的 set 物件是否小於或等於右邊的 set 物件。

bool operator!<=(const set <Key, Traits, Allocator>& left, const set <Key, Traits, Allocator>& right);

參數

left
set 類型的物件。

right
set 類型的物件。

傳回值

true 如果運算子左邊的集合小於或等於運算子右邊的集合,則為 ;否則 false為 。

備註

set 物件之間的比較是以其項目的成對比較為基礎。 兩個物件之間的小於或等於關聯性,是根據第一對不相等元素的比較。

範例

// set_op_le.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   set <int> s1, s2, s3, s4;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
      s4.insert ( i );
   }

   if ( s1 <= s2 )
      cout << "Set s1 is less than or equal to the set s2." << endl;
   else
      cout << "The set s1 is greater than the set s2." << endl;

   if ( s1 <= s3 )
      cout << "Set s1 is less than or equal to the set s3." << endl;
   else
      cout << "The set s1 is greater than the set s3." << endl;

   if ( s1 <= s4 )
      cout << "Set s1 is less than or equal to the set s4." << endl;
   else
      cout << "The set s1 is greater than the set s4." << endl;
}
Set s1 is less than or equal to the set s2.
The set s1 is greater than the set s3.
Set s1 is less than or equal to the set s4.

operator== (set)

測試運算子左邊的 set 物件是否等於右邊的 set 物件。

bool operator!==(const set <Key, Traits, Allocator>& left, const set <Key, Traits, Allocator>& right);

參數

left
set 類型的物件。

right
set 類型的物件。

傳回值

true 如果運算子左邊的集合等於運算子右邊的集合,則為 ;否則 false為 。

備註

set 物件之間的比較是以其項目的成對比較為基礎。 如果兩個 set 具有相同的項目數,且其個別項目的值相同,則它們會相等。 反之則為不相等。

範例

// set_op_eq.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   set <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i );
   }

   if ( s1 == s2 )
      cout << "The sets s1 and s2 are equal." << endl;
   else
      cout << "The sets s1 and s2 are not equal." << endl;

   if ( s1 == s3 )
      cout << "The sets s1 and s3 are equal." << endl;
   else
      cout << "The sets s1 and s3 are not equal." << endl;
}
The sets s1 and s2 are not equal.
The sets s1 and s3 are equal.

operator> (set)

測試運算子左邊的 set 物件是否大於右邊的 set 物件。

bool operator>(const set <Key, Traits, Allocator>& left, const set <Key, Traits, Allocator>& right);

參數

left
set 類型的物件。

right
set 類型的物件。

傳回值

true 如果運算子左邊的集合大於運算子右邊的集合,則為 ;否則 false為 。

備註

set 物件之間的比較是以其項目的成對比較為基礎。 兩個物件之間的大於關聯性是根據第一對不相等元素的比較。

範例

// set_op_gt.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   set <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
   }

   if ( s1 > s2 )
      cout << "The set s1 is greater than the set s2." << endl;
   else
      cout << "The set s1 is not greater than the set s2." << endl;

   if ( s1 > s3 )
      cout << "The set s1 is greater than the set s3." << endl;
   else
      cout << "The set s1 is not greater than the set s3." << endl;
}
/* Output:
The set s1 is not greater than the set s2.
The set s1 is greater than the set s3.
*/

operator>= (set)

測試運算子左邊的 set 物件是否大於或等於右邊的 set 物件。

bool operator!>=(const set <Key, Traits, Allocator>& left, const set <Key, Traits, Allocator>& right);

參數

left
set 類型的物件。

right
set 類型的物件。

傳回值

true 如果運算子左邊的集合大於或等於清單右邊的集合,則為 ;否則 false為 。

備註

set 物件之間的比較是以其項目的成對比較為基礎。 兩個物件之間的大於或等於關聯性,是根據第一對不相等元素的比較。

範例

// set_op_ge.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   set <int> s1, s2, s3, s4;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
      s4.insert ( i );
   }

   if ( s1 >= s2 )
      cout << "Set s1 is greater than or equal to set s2." << endl;
   else
      cout << "The set s1 is less than the set s2." << endl;

   if ( s1 >= s3 )
      cout << "Set s1 is greater than or equal to set s3." << endl;
   else
      cout << "The set s1 is less than the set s3." << endl;

   if ( s1 >= s4 )
      cout << "Set s1 is greater than or equal to set s4." << endl;
   else
      cout << "The set s1 is less than the set s4." << endl;
}
The set s1 is less than the set s2.
Set s1 is greater than or equal to set s3.
Set s1 is greater than or equal to set s4.

operator!= (multiset)

測試運算子左邊的 multiset 物件是否不等於右邊的 multiset 物件。

bool operator!=(const multiset <Key, Traits, Allocator>& left, const multiset <Key, Traits, Allocator>& right);

參數

left
multiset 類型的物件。

right
multiset 類型的物件。

傳回值

true 如果集合或多重集不相等,則為 ; false 如果 set 或 multiset 相等,則為 。

備註

multiset 物件之間的比較是以其項目之間的成對比較為基礎。 如果兩個 set 或 multiset 具有相同的項目數,且其個別項目的值相同,則它們會相等。 反之則為不相等。

範例

// multiset_op_ne.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i );
   }

   if ( s1 != s2 )
      cout << "The multisets s1 and s2 are not equal." << endl;
   else
      cout << "The multisets s1 and s2 are equal." << endl;

   if ( s1 != s3 )
      cout << "The multisets s1 and s3 are not equal." << endl;
   else
      cout << "The multisets s1 and s3 are equal." << endl;
}
The multisets s1 and s2 are not equal.
The multisets s1 and s3 are equal.

operator< (multiset)

測試運算子左邊的 multiset 物件是否小於右邊的 multiset 物件。

bool operator<(const multiset <Key, Traits, Allocator>& left, const multiset <Key, Traits, Allocator>& right);

參數

left
multiset 類型的物件。

right
multiset 類型的物件。

傳回值

true 如果運算子左邊的 multiset 嚴格小於運算符右邊的 multiset,則為 ;否則 false為 。

備註

multiset 物件之間的比較是以其項目的成對比較為基礎。 兩個物件之間的小於關聯性是根據第一對不相等元素的比較。

範例

// multiset_op_lt.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
   }

   if ( s1 < s2 )
      cout << "The multiset s1 is less than "
           << "the multiset s2." << endl;
   else
      cout << "The multiset s1 is not less than "
           << "the multiset s2." << endl;

   if ( s1 < s3 )
      cout << "The multiset s1 is less than "
           << "the multiset s3." << endl;
   else
      cout << "The multiset s1 is not less than "
           << "the multiset s3." << endl;
}
The multiset s1 is less than the multiset s2.
The multiset s1 is not less than the multiset s3.

operator<= (multiset)

測試運算子左邊的 multiset 物件是否小於或等於右邊的 multiset 物件。

bool operator!<=(const multiset <Key, Traits, Allocator>& left, const multiset <Key, Traits, Allocator>& right);

參數

left
multiset 類型的物件。

right
multiset 類型的物件。

傳回值

true 如果運算子左邊的 multiset 小於或等於運算子右邊的 multiset,則為 ;否則 false為 。

備註

multiset 物件之間的比較是以其項目的成對比較為基礎。 兩個物件之間的小於或等於關聯性,是根據第一對不相等元素的比較。

範例

// multiset_op_le.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> s1, s2, s3, s4;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
      s4.insert ( i );
   }

   if ( s1 <= s2 )
      cout << "The multiset s1 is less than "
           << "or equal to the multiset s2." << endl;
   else
      cout << "The multiset s1 is greater than "
           << "the multiset s2." << endl;

   if ( s1 <= s3 )
      cout << "The multiset s1 is less than "
           << "or equal to the multiset s3." << endl;
   else
      cout << "The multiset s1 is greater than "
           << "the multiset s3." << endl;

   if ( s1 <= s4 )
      cout << "The multiset s1 is less than "
           << "or equal to the multiset s4." << endl;
   else
      cout << "The multiset s1 is greater than "
           << "the multiset s4." << endl;
}
The multiset s1 is less than or equal to the multiset s2.
The multiset s1 is greater than the multiset s3.
The multiset s1 is less than or equal to the multiset s4.

operator== (multiset)

測試運算子左邊的 multiset 物件是否等於右邊的 multiset 物件。

bool operator!==(const multiset <Key, Traits, Allocator>& left, const multiset <Key, Traits, Allocator>& right);

參數

left
multiset 類型的物件。

right
multiset 類型的物件。

傳回值

true 如果運算子左邊的 multiset 等於運算符右邊的 multiset,則為 ;否則 false為 。

備註

multiset 物件之間的比較是以其項目的成對比較為基礎。 如果兩個 set 或 multiset 具有相同的項目數,且其個別項目的值相同,則它們會相等。 反之則為不相等。

範例

// multiset_op_eq.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i );
   }

   if ( s1 == s2 )
      cout << "The multisets s1 and s2 are equal." << endl;
   else
      cout << "The multisets s1 and s2 are not equal." << endl;

   if ( s1 == s3 )
      cout << "The multisets s1 and s3 are equal." << endl;
   else
      cout << "The multisets s1 and s3 are not equal." << endl;
}
The multisets s1 and s2 are not equal.
The multisets s1 and s3 are equal.

operator> (multiset)

測試運算子左邊的 multiset 物件是否大於右邊的 multiset 物件。

bool operator>(const multiset <Key, Traits, Allocator>& left, const multiset <Key, Traits, Allocator>& right);

參數

left
multiset 類型的物件。

right
multiset 類型的物件。

傳回值

true 如果運算子左邊的 multiset 大於運算符右邊的 multiset,則為 ;否則 false為 。

備註

multiset 物件之間的比較是以其項目的成對比較為基礎。 兩個物件之間的大於關聯性是根據第一對不相等元素的比較。

範例

// multiset_op_gt.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
   }

   if ( s1 > s2 )
      cout << "The multiset s1 is greater than "
           << "the multiset s2." << endl;
   else
      cout << "The multiset s1 is not greater "
           << "than the multiset s2." << endl;

   if ( s1 > s3 )
      cout << "The multiset s1 is greater than "
           << "the multiset s3." << endl;
   else
      cout << "The multiset s1 is not greater than "
           << "the multiset s3." << endl;
}
The multiset s1 is not greater than the multiset s2.
The multiset s1 is greater than the multiset s3.

operator>= (multiset)

測試運算子左邊的 multiset 物件是否大於或等於右邊的 multiset 物件。

bool operator!>=(const multiset <Key, Traits, Allocator>& left, const multiset <Key, Traits, Allocator>& right);

參數

left
multiset 類型的物件。

right
multiset 類型的物件。

傳回值

true 如果運算子左邊的 multiset 大於或等於列表右側的 multiset,則為 ;否則 false為 。

備註

multiset 物件之間的比較是以其項目的成對比較為基礎。 兩個物件之間的大於或等於關聯性,是根據第一對不相等元素的比較。

範例

// multiset_op_ge.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> s1, s2, s3, s4;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
      s4.insert ( i );
   }

   if ( s1 >= s2 )
      cout << "The multiset s1 is greater than "
           << "or equal to the multiset s2." << endl;
   else
      cout << "The multiset s1 is less than "
           << "the multiset s2." << endl;

   if ( s1 >= s3 )
      cout << "The multiset s1 is greater than "
           << "or equal to the multiset s3." << endl;
   else
      cout << "The multiset s1 is less than "
           << "the multiset s3." << endl;

   if ( s1 >= s4 )
      cout << "The multiset s1 is greater than "
           << "or equal to the multiset s4." << endl;
   else
      cout << "The multiset s1 is less than "
           << "the multiset s4." << endl;
}
The multiset s1 is less than the multiset s2.
The multiset s1 is greater than or equal to the multiset s3.
The multiset s1 is greater than or equal to the multiset s4.