目录

multimap::operator=

描述 (Description)

C ++函数std::multimap::operator=将元素从初始化列表复制到多图。

声明 (Declaration)

以下是std :: multimap :: operator = function form std :: map header的声明。

C++11

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

参数 (Parameters)

il - 初始化列表。

返回值

返回此指针

异常 (Exceptions)

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

时间复杂

线性即O(n)

例子 (Example)

以下示例显示了std :: multimap :: operator = function的用法。

#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
↑回到顶部↑
WIKI教程 @2018