(1) | pair<iterator,bool> insert (const value_type& val); |
(2) | template <class P> pair<iterator,bool> insert ( P&& val ); |
(3) | iterator insert ( const_iterator hint, const value_type& val ); |
(4) | template <class P> iterator insert ( const_iterator hint, P&& val ); |
(5) | template <class InputIterator> void insert ( InputIterator first, InputIterator last ); |
(6) | void insert ( initializer_list<value_type> il ); |
// unordered_map::insert #include <iostream> #include <string> #include <unordered_map> int main () { std::unordered_map<std::string,double> myrecipe, mypantry = {{"milk",2.0},{"flour",1.5}}; std::pair<std::string,double> myshopping ("baking powder",0.3); myrecipe.insert (myshopping); // copy insertion myrecipe.insert (std::make_pair<std::string,double>("eggs",6.0)); // move insertion myrecipe.insert (mypantry.begin(), mypantry.end()); // range insertion myrecipe.insert ( {{"sugar",0.8},{"salt",0.1}} ); // initializer list insertion std::cout << "myrecipe contains:" << std::endl; for (auto& x: myrecipe) std::cout << x.first << ": " << x.second << std::endl; std::cout << std::endl; return 0; } |
unordered_map::erase | 删除元素(公众成员函数) |
unordered_map::emplace | 构造和插入元素(公众成员函数) |
unordered_map::emplace_hint | 构造和插入元素并加提示(公众成员函数) |
unordered_map::operator= | 复制容器内容(公众成员函数) |