Reputation: 13
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}));
Upvotes: 1
Views: 652
Reputation: 812
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()
Upvotes: 1
Reputation: 456
Another way is you can use tuples.
multimap<int, std::tuple<std::string, std::string>> Multimap;
Multimap.insert(make_pair(number, std::make_tuple(name, secondname));
https://en.cppreference.com/w/cpp/utility/tuple
Upvotes: 0