const char* s = std::string("text").c_str();
std::cout << s << std::endl; //This will print nothing because the data
//isn't available any longer
A string cannot be made to use reference counted pointers internally. If you wish to use a pointer to its data, you must make sure the string survives. The only alternative is copying / moving the data out into another string object.