i want to remove overlaps string stored in vector<-string> for show only one element.
i sorted vector dictionary order and it work well.
and next for erase, i use code below.
for(auto iter = begin(vec); iter != end(vec); iter++) {
auto frontIter = (iter + 1);
if((*iter).compare(*frontIter) == 0)
vec.erase(iter);
}
but it erase only one overlap element.
if i input like a a a(3 strings) and all element of vector show a a(2 strings)
i think vec.erase(iter); of part have something wrong..
vec.erase()call invalidates all iterators that refer to (elements of)vecat or afteriter. Your code is assuming the iterators are still valid, so has undefined behaviour. In any event, look up the standard algorithmunique().unique()at reference,