remove duplicate characters in a string c++ stl code example
Example 1: c++ remove whitespace from string
#include <algorithm>
int main()
{
std::string str = "H e l l o";
str.erase(remove(str.begin(), str.end(), ' '), str.end());
std::cout << str; // Output Hello
return 0;
}
Example 2: removing repeated characters in a string c++
s.erase(std::unique(s.begin(), s.end()), s.end());