It is much easier to remove duplicates after sorting. In an unsorted array the duplicate could be anywhere. In a sorted array the duplicates are all nicely next to each other.
In fact there is another algorithm for removing duplicates from a sorted container.
Code:
#include <iostream>
#include <algorithm>
int main()
{
int arr[] = { 2, 1, 6, 4, 22, 4, 2, 1, 3 };
const unsigned max = sizeof(arr) / sizeof(arr[0]);
std::sort(arr, arr + max);
//std::unique only works if the array is sorted
const unsigned max_unique = std::unique(arr, arr + max) - arr;
for (unsigned i = 0; i != max_unique; ++i) {
std::cout << arr[i] << ' ';
}
//items in range max_unique...max are not valid
}