For example, i have the following string :
std::string s = "Hello, World!"
I want the address of the last element of s
which is '!'
.
I tried the following code, but it does not seem to output what I want it to.
std::cout << &s[s.length() - 1];
That outputs '!'
not it's address, the same happens with s.back()
Is it because of the formatting caused by std::cout
or is the problem elsewhere?
Basically I want a function that outputs the address of the last (and if possible, the first) element in a string.