Firstly the code listed as follow.
#include<string>
#include<stdio.h>
int main(){
const char *cs;
{
std::string s("123456");
cs = s.c_str();
printf("cs = %s\n",cs);
}
printf("cs = %s\n",cs);
return 0;
}
run it, and result as follow. (Linux gcc )
cs = 123456
cs = 123456
So, I don't know why the cs pointer is valid after the s is destroyed. in other words, the lifetime of pointer that point to c_str function in std::string.