C++ 對映庫 - operator!= 函式



描述

C++ 函式std::map::operator!=測試兩個對映是否相等。

宣告

以下是來自 std::map 標頭檔案的 std::map::operator!= 函式的宣告。

C++98

template <class Key, class T, class Compare, class Alloc>
bool operator!= ( const map<Key,T,Compare,Alloc>& m1,
                  const map<Key,T,Compare,Alloc>& m2);

引數

  • m1 - 第一個對映物件。

  • m2 - 第二個對映物件。

返回值

如果兩個對映不相等則返回 true,否則返回 false。

異常

此函式不丟擲異常。

時間複雜度

線性,即 O(n)

示例

以下示例演示了 std::map::operator!= 函式的使用。

#include <iostream>
#include <map>

using namespace std;

int main(void) {
   map<char, int> m1;
   map<char, int> m2;

   m1.emplace('a', 1);

   if (m1 != m2)
      cout << "Both maps not are equal." << endl;

   m1 = m2;

   if (!(m1 != m2))
      cout << "Both maps are equal." << endl;

   return 0;
}

讓我們編譯並執行上述程式,這將產生以下結果:

Both maps not are equal.
Both maps are equal.
map.htm
廣告