boost::trim in C++ library Last Updated : 06 Aug, 2024 Comments Improve Suggest changes Like Article Like Report This function is included in the "boost/algorithm/string" library. The Boost String Algorithms Library provides a generic implementation of string-related algorithms which are missing in STL. The trim function is used to remove all leading or trailing white spaces from the string. The input sequence is modified in place.trim_left(): Removes all leading white spaces from the string.trim_right(): Removes all trailing white spaces from the string.trim(): Removes all leading and trailing white spaces from the string.Syntax:Template:trim(Input, Loc);Parameters:Input: An input sequenceLoc: A locale used for 'space' classificationReturns: The modified input sequence without leading or trailing white spaces.Examples:Input: " geeks_for_geeks " Output: Applied left trim: "geeks_for_geeks " Applied right trim: " geeks_for_geeks" Applied trim: "geeks_for_geeks" Explanation: The trim_left() function removes all the leading white spaces.The trim_right() function removes all the trailing white spaces.The trim() function removes all the leading and trailing white spaces.Below is the implementation to remove white spaces from string using the function boost::trim(): C++ // C++ program to remove white spaces // from string using the function // boost::trim function #include <boost/algorithm/string.hpp> #include <iostream> using namespace boost::algorithm; using namespace std; // Driver Code int main() { // Given Input string s1 = " geeks_for_geeks "; string s2 = " geeks_for_geeks "; string s3 = " geeks_for_geeks "; // Apply Left Trim on string, s1 cout << "The original string is: \"" << s1 << "\" \n"; trim_left(s1); cout << "Applied left trim: \"" << s1 << "\" \n\n"; // Apply Right Trim on string, s2 cout << "The original string is: \"" << s2 << "\" \n"; trim_right(s2); cout << "Applied right trim: \"" << s2 << "\" \n\n"; // Apply Trim on string, s3 cout << "The original string is: \"" << s3 << "\" \n"; trim(s3); cout << "Applied trim: \"" << s3 << "\" \n"; return 0; } OutputThe original string is: " geeks_for_geeks " Applied left trim: "geeks_for_geeks " The original string is: " geeks_for_geeks " Applied right trim: " geeks_for_geeks" The original string is: " geeks_for_geeks " Applied trim: "geeks_for_geeks" Time Complexity: O(N)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article boost::trim in C++ library N newcybergypsy Follow Improve Article Tags : C++ CPP-Library CPP-Functions Practice Tags : CPP Similar Reads C++ Boost String Algorithms Library The Boost String Algorithms Library provides a generic implementation of string-related algorithms which are missing in STL. It is an extension to the algorithms library of STL and it includes trimming, case conversion, predicates and find/replace functions. All of them come in different variants so 3 min read boost::algorithm::one_of() in C++ library The one_of() function in C++ boost library is found under the header 'boost/algorithm/cxx11/one_of.hpp' which tests the elements of a sequence and returns true if exactly one of the element share the property given. It takes a sequence and a predicate, and returns true if the predicate returns true 2 min read boost::algorithm::all_of() in C++ library The all_of() function in C++ boost library is found under the header 'boost/algorithm/cxx11/all_of.hpp' which tests all the elements of a sequence and returns true if they all share a property. It takes a sequence and a predicate, and returns true if the predicate returns true when applied to every 2 min read boost::algorithm::any_of() in C++ library The any_of() function in C++ boost library is found under the header 'boost/algorithm/cxx11/any_of.hpp' which tests the elements of a sequence and returns true if they any of the elements share the property given. It takes a sequence and a predicate, and returns true if the predicate returns true fo 2 min read boost::algorithm::none_of() in C++ library The none_of() function in C++ boost library is found under the header 'boost/algorithm/cxx11/none_of.hpp' which tests all the elements of a sequence and returns true if all of them do not share a property. It takes a sequence and a predicate, and returns true if the predicate returns false when appl 2 min read Like