What is the preferred way to remove spaces from a string in C++? I could loop through all the characters and build a new string, but is there a better way?
For trimming, use boost string algorithms:
#include using namespace std; using namespace boost; // ... string str1(" hello world! "); trim(str1); // str1 == "hello world!"