fork download
  1. #include <boost/algorithm/string.hpp>
  2. #include <iostream>
  3. using namespace boost::algorithm;
  4. using namespace std;
  5.  
  6. // Driver Code
  7. int main()
  8. {
  9. // Given Input
  10. string s1 = " geeks_for_geeks ";
  11. string s2 = " geeks_for_geeks ";
  12. string s3 = "";
  13.  
  14. // Apply Left Trim on string, s1
  15. cout << "The original string is: \""
  16. << s1 << "\" \n";
  17. trim_left(s1);
  18. cout << "Applied left trim: \""
  19. << s1 << "\" \n\n";
  20.  
  21. // Apply Right Trim on string, s2
  22. cout << "The original string is: \""
  23. << s2 << "\" \n";
  24. trim_right(s2);
  25. cout << "Applied right trim: \""
  26. << s2 << "\" \n\n";
  27.  
  28. // Apply Trim on string, s3
  29. cout << "The original string is: \""
  30. << s3 << "\" \n";
  31. trim(s3);
  32. cout << "Applied trim: \"" << s3
  33. << "\" \n";
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5296KB
stdin
Standard input is empty
stdout
The 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: "" 
Applied trim: ""