What is the best way for getting the last element of a C++ std::string? I can think of two methods but I'm unsure whether the second is reliable. Any suggestions?
Thanks in advance.
1 2 3 4 5
// version 1
str[str.size() - 1];
// version 2 -- are there situations when this might not work?
*(str.end() - 1);