I want to check if a string is among the values of a map which holds vectors of strings as values
typedef std::map<std::string, std::vector<string>> ClusterDescription;
std::map<std::string, std::vector<string>> clusterDescription;
std::vector<string> vec1 = {"11", "22", "33"};
std::vector<string> vec2 = {"44", "55"};
std::vector<string> vec3 = {};
std::string key1 = "1";
std::string key2 = "2";
std::string key3 = "3";
clusterDescription.insert(std::make_pair(key1, vec1));
clusterDescription.insert(std::make_pair(key2, vec2));
clusterDescription.insert(std::make_pair(key3, vec3));
std::string ID = "44";
for (ClusterDescription::iterator it = clusterDescription.begin(); it != clusterDescription.end(); ++it)
{
std::vector<std::string> clusterMembers = it->second;
if(std::find(clusterMembers.begin(), clusterMembers.end(), ID) != clusterMembers.end())
{
std::cout<< " I received an msg, from the wrong head "<< std::endl; //FIXME:
break;
}
else
{
std::cout<< " I have not been included in any cluster yet "<< std::endl; //FIXME:
std::cout<< " sending joinmode msg "<< std::endl;
break;
}
}
Here the code works fine for the values: 11, 22, 33. But it fails for the other cases. What am I missing?
Aucun commentaire:
Enregistrer un commentaire