string s;
cout << s[s.length()-1] << endl;

s长度为零有问题
另外一种

string s;
char c=s.back();
string s;
cout << *s.rbegin() << endl;