Thoughts and tips for a daily coding life

2012/01/28

Removing unique chars from string in C++

January 28, 2012 Posted by Antanas Domarkas , , No comments
Needed to remove some duplicate char sequences from string and couldn't remember usage for unique function.
Basically got stuck with usage syntax =)

After half an hour of reading and searching got this:

std::string code = "some code wiiiiith dubbbblicate chaaaars";
code.erase(std::unique(code.begin(), code.end()), code.end());

Hope this will help other doomed soul.