Remove duplicates from a given string | CPP program to remove duplicate character from character array and print in sorted order ; create a set using string characters excluding ' \0' ; print content of the set ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; char * removeDuplicate ( char str [ ] , int n ) { set < char > s ( str , str + n - 1 ) ; int i = 0 ; for ( auto x : s ) str [ i ++ ] = x ; str [ i ] = ' \0' ; return str ; } int main ( ) { char str [ ] = " geeksforgeeks " ; int n = sizeof ( str ) / sizeof ( str [ 0 ] ) ; cout << removeDuplicate ( str , n ) ; return 0 ; }