Michael L Torrie wrote:
>> std::string itoa(int in){
>> std::stringstream out;
>> out << in;
>> return(out.str());
> ^^^^^^^^^^^^^^^^^^^
> nope. you can't do that.
Nevermind. This one would probably work, if out.str() returns a new
object and not a reference to some internal object within the out object.
>
>> }
>>
>> and
>>
>> char* itoa(int in){
>> std::stringstream out;
>> out << in;
>> return(out.rdbuf.c_str());
> ^^^^^^^^^^^^^^
> can't do that either, at least safely.
This one, though, is definitely bad. By the time the caller gets the
char *, it's already pointing to invalidated stack space. Good way to
get a segfault or worse a buffer overrun that could lead to bad things.
/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/