#include#include using namespace std; int main() { string str = " This is a string with spaces"; // Remove white spaces from the beginning of the string str.erase(0, str.find_first_not_of(" ")); cout << str << endl; return 0; }
#includeOutput: "This is a string with spaces" Package/library: Standard C++ Library (header file:#include using namespace std; int main() { string str = "This is a string with spaces "; // Remove white spaces from the end of the string str.erase(str.find_last_not_of(" ") + 1); cout << str << endl; return 0; }