Search code examples
c++multimap

How to store more than 2 values in multimap?


im stuck at a problem, How do we store 3 values through multimap. For example one int and 2 c++ strings. How do we store those 3 values. I tried making a struct and storing 2 strings and then passing it in multimap code as

struct names{ std::string name; std::string secondname; }; and done with

multimap<int, names>Multimap;

first take number from user, second take name from user, third take name form user and then

Multimap.insert(make_pair(number,{name,secondname}));


Solution

  • Please define type of pair too like this:

    struct names{ std::string name; std::string secondname; }; 
    multimap<int, names>Multimap;
    
    Multimap.insert(make_pair<int, names>(number,{"name","secondname"}) );
    // or simply you can use pair() too instead of make_pair()