簡體   English   中英

如何在地圖中搜索本身就是一對的鑰匙?

[英]How to search for a key which is a pair itself, in a map?

我想檢查地圖上是否存在鑰匙(本身就是一對)。

我是使用Map的新手,無法找到要檢查鍵(一對)的函數。

#include<bits/stdc++.h>
using namespace std;
#define  ll long long int
typedef pair<ll,ll> my_key_type;
typedef map<my_key_type,ll> my_map_type;
int  main()
{
    my_map_type ma;
    my_map_type::iterator it;
    ma.insert(make_pair(my_key_type(30,40),6));
    it=ma.find(30,40);
    if(it==ma.end())
    {
        cout<<"not present";
        return 0;
    }
    cout<<"present";
    return 0;   
}                   

我收到以下錯誤-

no matching function for call to ‘std::map<std::pair<long long int, long long int>, long long int>::find(int, int)’   it=ma.find(30,40);

使用時

it=ma.find(30,40);

編譯器不會自動將參數轉換為一對。 您必須明確地做到這一點。

it=ma.find(std::make_pair(30,40));

或更簡單的版本

it=ma.find({30,40});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM