I want to search for multiple strings in a vector at once.
i.e vector = “H” “H” “I” “I”
vector2 = “H” “I”
so i want to search vector with the contents of vector2 my code is below but i don’t think it is the best way. If all the strings are present then return a identifier so i know all strings are present.
could someone check the code below just to see if its correct 🙂 Thanks
std::vector<std::string> test;
test.push_back("YES");
test.push_back("YES");
test.push_back("NO");
test.push_back("NO");
std::vector<std::string> test1;
test1.push_back("YES");
test1.push_back("NO");
std::vector<std::string>::iterator it;
for(int i = 0; i < test1.size(); i++)
{
if(find (test.begin(), test.end(),test[i]) != test.begin() )
{
DCS_LOG_DEBUG("Some elements have appeared more than once...");
}
}
The comparison is incorrect. If you want to check if there is at least one element in the container instead of:
you should use:
because
findreturnstest.end()when it founds no match.If you want to check if more than one element exists use
count: