Remove characters from the first string which are present in the second string | C ++ program to remove duplicates ; we extract every character of string string 2 ; we find char exit or not ; if char exit we simply remove that char ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string removeChars ( string string1 , string string2 ) { for ( auto i : string2 ) { while ( find ( string1 . begin ( ) , string1 . end ( ) , i ) != string1 . end ( ) ) { auto itr = find ( string1 . begin ( ) , string1 . end ( ) , i ) ; string1 . erase ( itr ) ; } } return string1 ; } int main ( ) { string string1 , string2 ; string1 = " geeksforgeeks " ; string2 = " mask " ; cout << removeChars ( string1 , string2 ) << endl ; ; return 0 ; }