I have std::vector<std::string> textLines , which contains a large number of, for example, city names. I delete duplicates with:
using namespace std; vector<string>::iterator iter; sort(textLines.begin(), textLines.end()); iter = unique(textLines.begin(), textLines.end());
At this point, the repeating elements are all zero (empty) lines at the end of the vector with the same size as before unique() .
I delete them with
textLines.resize(distance(textLines.begin(), iter));
This works fine, but is there a way to keep deleted duplicates? It would be better (for me) if the duplicates were simply carried over to the end and not replaced by empty lines.
The new end is indicated by the iter returned from unique() , so there is no problem finding the new end of the vector.
In other words, I want to know which rows had duplicates and which did not.
source share