-1

I'm getting this error trying to do map.find(10,20) does anyonw knows how to do it

Error (active)  E0304   no instance of overloaded function "std::map<_Kty, 
_Ty, _Pr, _Alloc>::find [with _Kty=std::pair<int, int>, _Ty=std::tuple<int, int, int>, _Pr=std::less<std::pair<int, int>>, 
_Alloc=std::allocator<std::pair<const std::pair<int, int>, std::tuple<int, int, int>>>]" matches the argument list  Maps    
#include <iostream>
#include <map>
#include <string>


int main()
{
    std::map<std::pair<int, int>,std::tuple<int,int,int>> myMap;
    // Inserting data in std::map
    myMap[std::make_pair(10, 20)] = std::make_tuple(1,2,3);

    auto it = myMap.cbegin();
    for (auto const& it : myMap){ 
        std::cout << it.first.first << it.first.second << std::get<0>(it.second); 

    }


    auto search = myMap.find(10,20);
    return 0;
}
NathanOliver
  • 171,901
  • 28
  • 288
  • 402

1 Answers1

1

You need a std::pair as a key, not two ints. When you inserted the item, you correctly used std::make_pair. You'll need to do the same with the find member function or, as mentioned in the comments, wrap your key in braces. Both do the same thing; the first is more explicit, in the second case you're relying on implicit conversion to std::pair.

auto search = myMap.find(std::make_pair(10, 20));

or

auto search = myMap.find({10, 20});
ravnsgaard
  • 922
  • 1
  • 10
  • 20