|
|
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
|
|