I'm trying to make sense of the following output of the string.at()
function.
#include <iostream>
#include <string>
int main() {
std::string name = "abc";
std::cout << name.at(0) << '\n';
std::cout << &name.at(0) << '\n';
return 0;
}
This will output:
a
abc
I am confused as why &name.at(0)
will not return the address of the first char of the string, i.e. a
. Instead, it returns the complete string.
According to the doc, string::at
"returns a reference to the character at position pos in the string."