inserting element in unordered_map c++ code example
Example: insert in unordered_map
#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);
myrecipe.insert (std::make_pair<std::string,double>("eggs",6.0));
myrecipe.insert (mypantry.begin(), mypantry.end());
myrecipe.insert ( {{"sugar",0.8},{"salt",0.1}} );
std::cout << "myrecipe contains:" << std::endl;
for (auto& x: myrecipe)
std::cout << x.first << ": " << x.second << std::endl;
std::cout << std::endl;
return 0;
}