C++ 映射库 - operator= 函数



描述

C++ 函数std::multimap::operator= 将初始化列表中的元素复制到多重映射。

声明

以下是来自 std::map 头文件的 std::multimap::operator= 函数的声明。

C++11

multimap& operator= (initializer_list<value_type> il);

Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.

参数

il - 初始化列表。

返回值

返回 this 指针

异常

如果抛出异常,对容器没有影响。

时间复杂度

线性,即 O(n)

示例

以下示例演示了 std::multimap::operator= 函数的使用方法。

#include <iostream>
#include <map>

using namespace std;

int main(void) {
   multimap<char, int> m;

   m = {
         {'a', 1},
         {'a', 2},
         {'b', 3},
         {'c', 4},
         {'d', 5}
       };

   cout << "Multimap contains following elements" << endl;

   for (auto it = m.begin(); it != m.end(); ++it)
      cout << it->first << " = " << it->second << endl;

   return 0;
}

让我们编译并运行上述程序,这将产生以下结果:

Multimap contains following elements
a = 1
a = 2
b = 3
c = 4
d = 5
map.htm
广告