itoa'd you so?
Levi Pearson
levi at cold.org
Wed Sep 19 14:25:15 MDT 2007
Steve <smorrey at gmail.com> writes:
>
> I came up with 2 solutions which both amounted to roughly the same code.
>
> std::string itoa(int in){
> std::stringstream out;
> out << in;
> return(out.str());
> }
>
> and
>
> char* itoa(int in){
> std::stringstream out;
> out << in;
> return(out.rdbuf.c_str());
> }
>
> So my question is, what is wrong with this method (I haven't tested it
> so there may be a minor syntax error, but that aside)?
What's wrong with that method is that it's using the standard library,
which was explicitly not available. C++ kind of hides the fact that
you're essentially calling itoa() when you do out << in there, once
you go through the overloaded function that implements <<, etc.
So, try doing it again in plain C without using any standard library
functions.
--Levi
More information about the PLUG
mailing list