Is the following C++ code well-formed:
void consumer(char const* p)
{
std::printf(\"%s\", p);
}
std::string random_string_generator()
{
// returns a ran
The temporary std::string's lifetime extends just beyond the point where consumer returns, so it is safe to use anything on that string directly from within consumer. What is not OK is to store the value that c_str returns and try to use it later (the temporary will have been destroyed, and we can only guess what you will find at the other end of the pointer).