jeudi 23 juin 2016

char and char& no matching function for call

In order to compare if two string contain a same char, I was trying to loop through a string a and put the chars into a map. As C++ don't have set (like python), I have to give the keys a value.

So this is what I did.

    string a = "abc";
    unordered_map<char,int> m;

    for (auto i:a){
        m.insert(a,1);
    }

But then there is an error: no matching function for call to ‘std::unordered_map<char, int>::insert(char&, int)’

I don't quite understand what can I do here :) Hope some one can help!

Aucun commentaire:

Enregistrer un commentaire