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?
Removes all whitespace characters such as tabs and line breaks (C++11):
string str = " \n AB cd \t efg\v\n"; str = regex_replace(str,regex("\\s"),"");