Possible Duplicate:
Remove spaces from std::string in C++
I am starting to learn cpp. Hope you guys can help me. Right now, I am having a problem with strings. I get input from the user and want to ignore the white space and combine the string. Here it is:
getline(cin, userInput);
If user input is: Hello my name is
I want to combine to: Hellomynameis
Is there a quick way to do that. Your help will be much appreciated. Thanks.
EDIT:
And, for another case: if the user input is: keyword -a argument1 argument2 argument3
How do I separate the words, because I want to check what are the “keyword”, “option”, and the arguments.
You can use:
The algorithm only changes the values and not the container contained values, So you need to call
string::eraseto actually modify the length of the container after callingremove_if.or if you are a Boost Fan, You can simple use: