I was wondering is there any function to compare 2 string vectors to return the number of different(or the same) elements? Or i have to iterate over both of them and test it
I don't know of an existing function but writing one yourself shouldn't be too much trouble.
int compare(const vector& left, const vector& right) {
auto leftIt = left.begin();
auto rightIt = right.begin();
auto diff = 0;
while (leftIt != left.end() && rightIt != right.end()) {
if (*leftIt != *rightIt) {
diff++;
}
leftIt++;
rightIt++;
}
// Account for different length vector instances
if (0 == diff && (leftIt != left.end() || rightIt != right.end())) {
diff = 1;
}
return diff;
}
Notes
std:: prefix for brevityvector instances of different lengths