Boost logo

Boost Users :

Subject: Re: [Boost-users] Conversion from numeric type to const char*
From: Roman Perepelitsa (roman.perepelitsa_at_[hidden])
Date: 2012-01-30 08:55:31

2012/1/30 Claude <clros_at_[hidden]>

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

Depends how you use the value.

  // Safe.

  const char* s = boost::lexical_cast<std::string>(myNumericVar).c_str();
  // Don't do this! Here 's' is a dangling pointer; the string has already
  // been destroyed.

Roman Perepelitsa.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at