Pete said:
Yup. You have to know something about conversions to get conversions right.
This is worrying. What about the C++ aim to help occasional and novice
programmers? (which is very relevent to this newsgroup BTW)?
To be portable you would either have to #ifdef dependent on platform or
make sure that your buffer would hold the largest possible int at least
till it gets bigger. I assume that your own stringent performance
standards wouldnt consider allowing you to waste stack space so you'd
have to use some sort of sizeof and then calculate either manually or
in code which means checking its correct, bearing in mind terminators,-
signs etc, similarly write a long et al version too and try to call the
right version (see below). In fact its pretty tedious to do all that
and check its correct and now what are you going to do with the char
array result anyway? Why bother? Let an ostringstream do the work and
spend brain power on more important things.
The other major advantage (apart from the very important one of
automatic resource management) of a stringstream is that you can make
the integer type a template parameter, which means it beats your write
once rule as using C functions you would need to rewrite for long and
unsigned long, double and float, all which may have different lengths
of ascii representation afaik.
We're talking about converting an int. Write it once, get it right, end
of discussion.
Then do same for a long, an unsigned long, a float, a double etc etc...
Then check all your buffer lengths... etc etc.
There may not be. Doesn't affect this discussion.
Nope. Write it once, get it right. No undefined behavior.
Oh, you meant "less opportunity to screw up if you're careless". Well,
that's true. Programming isn't a job for careless people.
If you have never made a careless mistake in your code then you must be
exceptional, but if only people that have never made coding mistakes
are allowed to code C++ I think the language is dead and you may soon
be the only C++ programmer. No offence to anyone else that has never
made a typo intended of course.
Of course then there would be no need for diagnostics from the compiler
as you and the other perfect programmer dont need them.
Again what about making the language accessible to occasional and
novice programmers?
Easier isn't the only goal, especially when any competent programmer
ought to be able to convert an int to a string with very little effort.
Easier and catching mistakes are very important goals. Thats basically
what high level programming is all about.
I use them too. They are very convenient IMO.
regards
Andy Little