|
|
Invisible <voi### [at] devnull> wrote:
> Warp wrote:
> > No need for atoi(). You can use stringstreams, as I wrote in the other
> > post.
> I did think using a C function seemed a little bogus.
There's merit in those C functions, though: They are much more efficient
than using stringstreams. (For one, they parse the string *in place*,
rather than copying the string around in memory.)
Of course their usage is more difficult.
> (For one thing, AFAIK, there is *no way* to know whether atoi()
> succeeded or failed; if it "fails", you get a zero. So was the string
> actually a zero, or did the conversion fail??)
Another C function can be used to both parse an integer from a string
and know if there was one: strtod(). However, its usage is even more
complicated than atoi().
--
- Warp
Post a reply to this message
|
|