Programming Tips - C/C++: How do I get the last character of a std::string ?

Date: 2010may14 Language: C/C++ Level: novice Q. C/C++: How do I get the last character of a std::string ? A. Like this:
char getLastChar(std::string &s) { if (s.length() == 0) return '\0'; return s[s.length() - 1]; }
Example Use:
void exampleUse() { const char c = getLastChar("hello world"); printf("last char is %c\n", c); }