Convert double to string

J

JKop

What's the best method to use?

I've searched the web a bit and all I've come up with is "sprintf".

Also, for the converse, ie. string to double, is "atof" the way to go?


Kind Regards,

JKop
 
B

benben

What's the best method to use?

I've searched the web a bit and all I've come up with is "sprintf".

Also, for the converse, ie. string to double, is "atof" the way to go?


Kind Regards,

JKop

You can use a string stream.

ben
 
T

Thomas Tutone

JKop said:
What's the best method to use?

I've searched the web a bit

But apparently not the FAQ - usually a better place to start.
and all I've come up with is "sprintf".
http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.1

Also, for the converse, ie. string to double, is "atof" the way to go?

Again, a quick perusal of the FAQ would answer that:

http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2


Best regards,

Tom
 
K

Kev

JKop said:
What's the best method to use?

I've searched the web a bit and all I've come up with is "sprintf".

Also, for the converse, ie. string to double, is "atof" the way to go?

Boost libraries are a good choice for simple conversions. Look for
lexical_cast. sstream is a good choice for formatted strings. ex: int +
string + anotherint + anotherstring : "12 eggs is the same as 1 dozen
eggs."
 
M

mlimber

Kev said:
Boost libraries are a good choice for simple conversions. Look for
lexical_cast. sstream is a good choice for formatted strings. ex: int +
string + anotherint + anotherstring : "12 eggs is the same as 1 dozen
eggs."

For a comparison of boost::lexical_cast and the various other options,
see Herb Sutter's article:

http://www.gotw.ca/publications/mill19.htm

Cheers! --M
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top