Boost logo

Boost Users :

Subject: Re: [Boost-users] Conversion from numeric type to const char*
From: Brian Allison (brian.w.allison_at_[hidden])
Date: 2012-01-30 08:40:29


On Mon, Jan 30, 2012 at 8:17 AM, Claude <clros_at_[hidden]> wrote:

> What is the better way for convert a numeric type into a const char *?
> I use:
>
> (boost::lexical_cast<std::string>(myNumericVar)).c_str()
>
> It is a good idea?
>
>
Using a *const char ** is prone to Undefined Behaviors. If there's a way to
use *std::string *instead, then try to do that.

But - if you *must *use a *const char ** [say for a 3rd party interface
that requires it] then that's as good as any method.

Be aware of the potential for an exception, and be ready to deal with it.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net