- Use an
std::vector instead of an array, so you can erase items1.
- If you don't need to maintain the original order, it's probably easiest to sort, then use
std::unique to eliminate the duplicates.
Code could look something like this:
std::vector<int> numbers;
srand(time(NULL));
std::generate_n(std::back_inserter(numbers), 10, rand);
std::sort(numbers.begin(), numbers.end());
std::copy(numbers.begin(), std::unique(numbers.begin(), numbers.end()),
std::ostream_iterator<int>(std::cout, "\t"));
// Or, as @Chris pointed out:
std::unique_copy(numbers.begin(), numbers.end(),
std::ostream_iterator<int>(std::cout, "\t"));
Note that since std::unique returns an iterator to the end of the range of unique numbers, we don't actually need to erase the others at all -- we can just use that as the end of the range we display.
Also note that as I've generated the numbers here, it would actually be pretty unusual to remove anything -- given the range of numbers produced by a typical implementation of rand(), it would be fairly unusual to see it produce any duplicates in only 10 iterations.
If you do need to maintain the original order, you have a couple of choices. One is to insert each item in a std::set (or std::unordered_set) as you print it out, and only print it out of inserting in the set was successful (i.e., it wasn't previously present).
1. Though that's only one of many reasons to prefer std::vector over an array.