POV-Ray : Newsgroups : povray.off-topic : My first C++ program : Re: My first C++ program Server Time
30 Sep 2024 19:26:22 EDT (-0400)
  Re: My first C++ program  
From: Warp
Date: 19 Sep 2008 11:35:36
Message: <48d3c6c7@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.