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\\
In the case of an empty string, your code assumes that adding 1 to string::npos gives 0. string::npos is of type string::size_type, which is unsigned. Thus, you are relying on the overflow behaviour of addition.
string::npos
string::size_type