9 Sep
2009
9 Sep
'09
12:19 p.m.
On Tue, 08 Sep 2009 19:35:06 +0200, Robert Ramey
I would not expect this to work.
const char* const_temp = temp.c_str( );
provides a cont char * - but this pointer is only temporary and becomes invalid when the function creating it returns. Hence the run time error.
I believe const_temp is valid here, up to exit of code block it resides. Perhaps you confused this code with the following one, which is wrong because the temporary 'str' std::string is then destroyed just after it has been created, i.e.: const char* const_temp = str( boost::format("x:%1% y:%2%") % _x % _y ).c_str( ); and const_temp points to a data buffer of an already destroyed std::string. Greetings, Luca