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?
You can use this solution for removing a char:
#include #include using namespace std; str.erase(remove(str.begin(), str.end(), char_to_remove), str.end());