#include <algorithm>
#include <string>
#include <cctype> // 用于std::isspace std::string removeSpaces(std::string str) {str.erase(std::remove_if(str.begin(), str.end(), ::isspace), str.end());return str;
}int main()
{string str = " helo world ";string strtmp = removeSpaces(str);printf("%s\n",strtmp.c_str());system("pause");return 0;
}
结果: