Search
 
SCRIPT & CODE EXAMPLE
 

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);
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: cpp rand 
Cpp :: find character in string c++ 
Cpp :: binary exponentiation modulo m 
Cpp :: c++ triangle 
Cpp :: prime number in c++ 
Cpp :: range of long long in c++ 
Cpp :: convert string to char c++ 
Cpp :: save all output in log file c cpp 
Cpp :: how to get last element of set in c++ 
Cpp :: c++ round number up 
Cpp :: c++ rule of five 
Cpp :: integer type validation c++ 
Cpp :: lcm function c++ 
Cpp :: c++ memory leak 
Cpp :: c++ map loop through key value 
Cpp :: Appending a vector to a vector in C++ 
Cpp :: c++ open file 
Cpp :: c++ reverse integer 
Cpp :: how to use decrement operator in c++ 
Cpp :: run c++ program in mac terminal 
Cpp :: C++ Volume of a Sphere 
Cpp :: C++ Swap 2 Variables Without Using 3rd Variable 
Cpp :: vector fin element c++ 
Cpp :: primes in range cpp 
Cpp :: cpp std list example 
Cpp :: ubuntu dotnet core install 
Cpp :: sort 0 1 2 leetcode 
Cpp :: c++ vectors 
Cpp :: c++ cout format 
Cpp :: rotate array cpp 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =