C ++中的Unordered_multimap运算子=

C ++函数std::unordered_multimap::operator =()通过替换旧内容,将新内容分配给unordered_multimap,并在必要时修改大小。

以下是std::unordered_map()标头中的std::unordered_multimap::operator =()函数的声明。

C ++ 11(语法)

unordered_multimap& operator=(const unordered_multimap& umm);

参数

umm - Another unordered_multimap object of same type.

返回值

Returns this pointer.

范例程式码

#include <iostream>
#include <unordered_map>
using namespace std;
int main(void) {
   unordered_multimap umm1 = {
      {'a', 1},
      {'b', 2},
      {'c', 3},
      {'d', 4},
      {'e', 5},
   };
   unordered_multimap umm2;
   umm2 = umm1;
   cout << "Unordered multimap contains following elements" << endl;
   for (auto it = umm2.begin(); it != umm2.end(); ++it)
   cout << it->first << " = " << it->second << endl;
   return 0;
}

输出结果

Unordered multimap contains following elements
e = 5
a = 1
b = 2
c = 3
d = 4