Answers for "insert only unique values into vector"

C++
0

insert only unique values into vector

std::vector<std::string> name;

....
if (std::find(name.begin(), name.end(), someName) == name.end()) {
  // someName not in name, add it
  name.push_back(someName);
}
Posted by: Guest on November-01-2020

Browse Popular Code Answers by Language