 |
|
 |
|
On Mon, 30 Jan 2012 14:55:31 +0100, Roman Perepelitsa <...@gmail.com
2012/1/30 Claude <...@tiscali.it
Depends how you use the value.
// Safe.
puts(boost::lexical_cast<std::string
const char* s = boost::lexical_cast<std::string // Don't do this! Here 's' is a dangling pointer; the string has already
// been destroyed.
puts(s);
Roman Perepelitsa.
<div class="gmail_quote"
What is the better way for convert a numeric type into a const char *?<br I use:<br<br (boost::lexical_cast<std::string>(myNumericVar)).c_str()<br<brIt is a good idea?</blockquote
<div
<div
_______________________________________________
Boost-users mailing list
Boos...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
|
|
 |
|
 |
 |
|
 |
|
On Mon, 30 Jan 2012 11:27:16 -0500, Jeff Flinn <...@gmail.com
If you absolutely need to fill a char array use std::string's copy
method for that:
char buf[100];
boost::lexical_cast<std::string
See Josutti's The C++ Standard Library 11.2.4
Alternatively boost::iostreams::array_sink to directly stream to a char
buffer.
Jeff
_______________________________________________
Boost-users mailing list
Boos...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
|
|
 |
|
 |
 |
|
 |
|
On Mon, 30 Jan 2012 15:05:19 +0100, Roman Perepelitsa <...@gmail.com
2012/1/30 Claude <...@tiscali.it
You could, although it's usually better to keep std::string and let it care
about memory management. When you need to pass const char* to a C function
(e.g., puts), use c_str().
Roman Perepelitsa.
<div class="gmail_quote"
Ok. I could use strcpy() to copy the .c_str() result in my char array?</blockquote
<div
_______________________________________________
Boost-users mailing list
Boos...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
|
|
 |
|
 |
 |
|
 |
|
On Mon, 30 Jan 2012 08:40:29 -0500, Brian Allison <...@gmail.com
On Mon, Jan 30, 2012 at 8:17 AM, Claude <...@tiscali.it
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.
<div class="gmail_quote"What is the better way for convert a numeric type into a const char *?<br I use:<br<br (boost::lexical_cast<std::string>(myNumericVar)).c_str()<br<brIt is a good idea?<br<font color="#888888"<br
_______________________________________________
Boost-users mailing list
Boos...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
|
|
 |
|
 |
|
|