We can use std:unique to remove duplicate elements although std:unique removes only the consecutive duplicate elements but we can use it to delete all the duplicate elements in the vector by applying logic in the program. So what we need to do is just sort the array before applying std::unique such that all equal elements become consecutive and now we have std:unique to remove all duplicate consecutive elements. Below is the logic

#include <vector> #include <algorithm> using namespace std; int main() { vector<int> v = { 1, 2, 4, 4, 10, 1, 2, 4, 7, 7}; vector<int>::iterator dup; // Sorting the array std::sort(v.begin(), v.end()); // Now v becomes 1 1 2 2 4 4 4 7 7 10 // Using std::unique dup = std::unique(v.begin(), v.begin() + 10); // Now v becomes {1 2 4 7 10 * * * * *} // * here will remain in unspecified state // Resizing the vector so as to remove the undefined terms v.resize(std::distance(v.begin(), dup)); // Displaying the vector after applying std::unique for (dup = v.begin(); dup != v.end(); ++dup) { cout << *dup << " "; } return 0; } Output 1 2 4 7 10

If you find have any feedback Please leave a comment.