Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ vector add only unique elements

#include <algorithm>
#include <vector>
std::vector<int> vec;

if (std::find(vec.begin(), vec.end(), key) == vec.end()) {
  // if key not in vec, add it
  vec.push_back(key);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #vector #add #unique #elements
ADD COMMENT
Topic
Name
9+4 =