C++ Program To Remove Duplicate Characters From Given String

 What is Duplicate Characters?

Duplicate Character means repeating characters.

In these program we will remove the characters that are present more than once.

string example, string example in c++, c++ programs, string, c++ programs


Program:

#include <iostream>
using namespace std;

int main()
{
    string s = "Scrupulously";

    for(int i = 1; i < s.length(); i++)
    {
        for(int j = 0; j < i; j++)
        {
            if(s[j] == s[i])
            {   //erase is an inbuilt function used to erase char of given index
                s.erase(i,1);
                
                i--;
            }            
        }
    }

    cout << s << endl;;

    return 0;
}

Output:

Scruplosy
Learn more about string here.

C++ Program To Remove Duplicate Characters From Given String C++ Program To Remove Duplicate Characters From Given String Reviewed by Beast Coder on March 26, 2021 Rating: 5

No comments:

Powered by Blogger.