Insert into a map

I hope that someone could help me. So I know that in std::unordered_map<int, std::pair<int, int>> output;. I can insert like this : output[key] = {value, value1};, but can I use the insert method to do this ? Could someone please help me ?

Upvotes: 0

Views: 63

Answers (2)

TonySalimi
TonySalimi

Reputation: 8427

Or simply:

#include <unordered_map>

int main()
{
   std::unordered_map<int, std::pair<int, int>> output;

   output[5] = { 10, 15 }; // your way
   output.insert({ 10, {20,30} }); // using brace intializer
   output.insert(std::make_pair(15, std::make_pair(30, 45))); // using make_pair
}

Upvotes: 1

Tanya
Tanya

Reputation: 88

You can do something like:

output.insert(pair<int, pair<int, int>>(1,pair<int, int>(3,4)));

See this: http://www.cplusplus.com/reference/map/map/insert/

Upvotes: 1

Related Questions