jeudi 28 juillet 2016

How to check if map.find() result is end C++?

I have a map

std::map<long long, string> directory;

I am trying to find a specific number, if that number is found in the map assign it to a variable. But it seems the if condition is not working, its entering the if even when the number is not found which is causing error. Whats missing ?

        auto it = directory.find(12345);
        string response = "value not found"
        if (it != directory.end());
        {
           response = it ->second;
        }

Aucun commentaire:

Enregistrer un commentaire