How can I access individual elements in a std::string with pointers? Is it possible without type casting to a const char *?
#include <iostream> #include <string> using namespace std; int main() { // I'm trying to do this... string str = "This is a string"; cout << str[2] << endl; // ...but by doing this instead string *p_str = &str; cout << /* access 3rd element of str with p_str */ << endl; return 0; }