POV-Ray : Newsgroups : povray.off-topic : My first C++ program : Re: My first C++ program Server Time
1 Oct 2024 00:03:58 EDT (-0400)
  Re: My first C++ program  
From: Warp
Date: 20 Sep 2008 04:49:55
Message: <48d4b932@news.povray.org>
Slime <fak### [at] emailaddress> wrote:
> atoi( mystring.c_str() )

> to convert to an integer. This is what I always use, though I see there are 
> other ways to do it.

  The problem is that with atoi() you can't know if there was an integer
in that string in the first place. If there wasn't, it just returns zero,
and you can't know if there was a zero in the string or something which
was not a parseable number.

  (And no, it's not enough to check if mystring[0] == '0'. There are a
multitude of other ways for a valid number 0 to be in the string.)

  This might be very relevant if you are checking if there was a number
of something else in the string, and act accordingly.

-- 
                                                          - Warp


Post a reply to this message

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