mardi 11 mai 2021

How to implement the below function getValue(m) for multimap in C++

#include<bits/stdc++.h>
using namespace std;
void getValue(multimap<int,string> &m){
    for(auto &mValue : m){
        cout<<mValue.first<<" "<<mValue.second<<endl;
    }
}
int main(){
    int n;
    cin>>n;
    multimap<int,string> m;
    
    for(int i=0;i<n;i++){
        int num;
        string str;
        cin>>num;
        getline(cin,str);
        m.insert(make_pair(num,str));
    }
    

    getValue(m);
    return 0;
}

Error : invalid initialization of reference of type ‘std::map >&’ from expression of type ‘std::multimap >’ getValue(m);

Aucun commentaire:

Enregistrer un commentaire