http://www.cplusplus.com/reference/map/
std::multimap::operator=
http://www.cplusplus.com/reference/map/multimap/operator=/
#include <iostream>
#include <map>
int main ()
{
std::multimap<char,int> foo,bar;
foo.insert(std::make_pair('x', 32));
foo.insert(std::make_pair('y', 64));
foo.insert(std::make_pair('y', 96));
foo.insert(std::make_pair('z', 128));
foo.insert({'b', 16});
foo.insert({'a', 8});
bar = foo; // bar now contains 6 ints
foo.clear(); // and first is now empty
std::cout << "Size of foo: " << foo.size() << '\n';
std::cout << "Size of bar: " << bar.size() << '\n';
// 遍历
for (auto x : bar) {
std::cout << x.first << ' ' << x.second << std::endl;
}
return 0;
}
运行结果:
Size of foo: 0
Size of bar: 6
a 8
b 16
x 32
y 64
y 96
z 128
map是按key排序的
http://cpp.sh/