Answers for "how to filter for unique vector elements c++"

8

erase duplicates and sort a vector

sort( vec.begin(), vec.end() );
vec.erase( unique( vec.begin(), vec.end() ), vec.end() );
Posted by: Guest on May-20-2020
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

Code answers related to "how to filter for unique vector elements c++"

Browse Popular Code Answers by Language