Browse - programming tips - c++ get last character of std stringDate: 2010may14 Language: C/C++ Level: beginner Q. How do I get the last charater of a std::string ? A. Like this: std::string mystring; char last_char; last_char = mystring[mystring.length()-1]; You can make function that does it: inline char getlastchar(std::string &s) { if (s.length() == 0) return '\0'; return s[s.length()-1]; }
Add a commentSign in to add a comment |