removing repeated characters in a string c++

C++
s.erase(std::unique(s.begin(), s.end()), s.end());void replace(string s)
{
    int length = s.length();

    for (int i = 0; i < length; i ++)
    {
        if (s[i] == s[i + 1])
        {
            s.erase(1+i);

        }

    }
    cout << s << endl;
}
Source

Also in C++: