I have simple code to trim the string
std::string TrimEnd(const std::string& str, const std::string& chars)
{
std::string trimmed = str;
int index = 0;
if((index = trimmed.find_last_not_of(chars)) < trimmed.length() - 1)
trimmed.erase(index + 1);
return trimmed;
}
I use references for arguments and value for function return. Is there any preference to use pointers instead? In my case a copy of the trimmed string is returned. In some functions const reference is returned.
No, not in a general sense. If you need to be able to pass in a NULL-ified pointer, or need to do some pointer arithmetic on the parameter, pass a pointer. Otherwise, pass references by default.