Remove duplicates from a string using STL in C++ Last Updated : 28 May, 2019 Comments Improve Suggest changes Like Article Like Report Given a string S, remove duplicates in this string using STL in C++ Examples: Input: Geeks for geeks Output: Gefgkors Input: aaaaabbbbbb Output: ab Approach: The consecutive duplicates of the string can be removed using the unique() function provided in STL. Below is the implementation of the above approach. CPP #include <bits/stdc++.h> using namespace std; int main() { string str = "aaaaabbbbbb"; sort(str.begin(), str.end()); // Using unique() method auto res = unique(str.begin(), str.end()); cout << string(str.begin(), res) << endl; } Output: ab Comment More infoAdvertise with us Next Article Remove duplicates from a string using STL in C++ C code_r Follow Improve Article Tags : C++ STL cpp-strings Practice Tags : CPPcpp-stringsSTL Similar Reads Remove all occurrences of a character from a string using STL Given a string S and a character C, the task is to remove all the occurrences of the character C from the given string. Examples: Input:vS = "GFG IS FUN", C = 'F' Output:GG IS UN Explanation: Removing all occurrences of the character 'F' modifies S to "GG IS UN". Therefore, the required output is GG 2 min read std::string::remove_copy(), std::string::remove_copy_if() in C++ remove_copy() It is an STL function in c++ which is defined in algorithm library. It copies the elements in the range [first, last) to the range beginning at result, except those elements that compare equal to given elements. The resulting range is shorter than [first,last) by as many elements as ma 5 min read Remove Leading Zeros From String in C++ Given a string of digits, remove leading zeros from it. Examples: Input : 00000123569 Output : 123569 Input : 000012356090 Output : 12356090 In this article, we will use two string functions i.e, string erase and stoi() to remove leading zeros from the string. 1. Using String Erase FunctionCount tra 2 min read Extract all integers from string in C++ Given a string, extract all integers words from it. Examples : Input : str = "geeksforgeeks 12 13 practice" Output : 12 13 Input : str = "1: Prakhar Agrawal, 2: Manish Kumar Rai, 3: Rishabh Gupta" Output : 1 2 3 Input : str = "Ankit sleeps at 4 am." Output : 4 The idea is to use stringstream:, objec 2 min read string shrink_to_fit() function in C++ STL The C++ Standard Template Library (STL) provides a variety of useful classes and functions for working with data structures, including the std::string class for manipulating strings. One of the features of the std::string class is the shrink_to_fit() function, which allows developers to reduce the a 3 min read Like