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?
#include using namespace std; int main() { . . s.erase( remove( s.begin(), s.end(), ' ' ), s.end() ); . . }
Reference taken from this forum.