F
Flyingaway
I am just wondering what is the most elegant and efficient way to do
such type conversion.
Thanks,
Flyingway
such type conversion.
Thanks,
Flyingway
Consider using boost::lexical_castFlyingaway said:I am just wondering what is the most elegant and efficient way to do
such type conversion.
Ivan said:Consider using boost::lexical_cast
See: http://www.boost.org/libs/conversion/lexical_cast.htm
For maximum efficiency, one could use a statically allocated
buffer and the functions atof (in <cstdlib>) and ftoa(when
available, otherwise sprintf). But for the latter you need
to be very careful with buffer overflows - using snprintf
may help...
Stu said:// Cast to string...
ss >> some_float;
ss << some_string;
Why not just use a stringstream? Something like:
Consider using boost::lexical_cast
See: http://www.boost.org/libs/conversion/lexical_cast.htm
For maximum efficiency, one could use a statically allocated
buffer and the functions atof (in <cstdlib>) and ftoa(when
available, otherwise sprintf). But for the latter you need
to be very careful with buffer overflows - using snprintf
may help...
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.