I\'m currently using the following code to right-trim all the std::strings in my programs:
std::strings
std::string s; s.erase(s.find_last_not_of(\" \\n\\r\\
Here's what I came up with:
std::stringstream trimmer; trimmer << str; trimmer >> str;
Stream extraction eliminates whitespace automatically, so this works like a charm. Pretty clean and elegant too, if I do say so myself. ;)