POV-Ray : Newsgroups : povray.off-topic : My first C++ program : Re: My first C++ program Server Time
30 Sep 2024 21:32:36 EDT (-0400)
  Re: My first C++ program  
From: Nicolas Alvarez
Date: 19 Sep 2008 19:07:41
Message: <48d430bc@news.povray.org>
Invisible 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.
> 
> (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??)

atoi is always a bad idea.

If you're writing C, you should use strtol instead. If you're writing C++,
you should use a stringstream instead.

Or use boost lexical_cast, which looks like a cast but works with streams to
do string-number conversions. But any boost library involves lots of
inter-library dependencies, and would surely increase your compilation
times (the compiler has to untangle all the templated mess :P). So just
stick to streams.


Post a reply to this message

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