the first cerr is printing hello but the second one is printing nothing, it seems that when string t1 is going out of scope and deleting t2 is affected so it looks like when we do t2=(char*)t1.c_str(); t1.c_str() is returning just a pointer to the stiring in it not a pointer to another copy so when it gets destroyed t2 is pointing to nothing :SCode:char *t2;
{
string t1="hello";
t2=(char*)t1.c_str();
cerr<<t2<<"\n";
}
cerr<<t2<<"\n";
1- is what I saidtrue
2- why does this happen, it seems so counter intuitive (why would they do it as so?)
3- how can I get over that? (I need to return t2 afterwards)
4- why didn't I get an error or garbage output when I printed t2 the second time I mean no body put t2=NULL so its still pointing to garbage :S
thanks in advance

