Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert double to string

3 views
Skip to first unread message

JKop

unread,
Sep 16, 2005, 9:42:30 AM9/16/05
to

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

Tim Love

unread,
Sep 16, 2005, 9:51:17 AM9/16/05
to
JKop <NU...@NULL.NULL> writes:


>What's the best method to use?

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

Try the FAQ
http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.1

benben

unread,
Sep 16, 2005, 9:53:50 AM9/16/05
to

You can use a string stream.

ben


Richard Herring

unread,
Sep 16, 2005, 10:12:52 AM9/16/05
to
In message <aZzWe.15565$R5....@news.indigo.ie>, JKop <NU...@NULL.NULL>
writes

>
>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?
>
#include <sstream>

--
Richard Herring

Thomas Tutone

unread,
Sep 16, 2005, 10:24:11 AM9/16/05
to
JKop wrote:

> 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

Kev

unread,
Sep 16, 2005, 1:32:33 PM9/16/05
to
JKop <NU...@NULL.NULL> wrote in news:aZzWe.15565$R5....@news.indigo.ie:

> 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."

mlimber

unread,
Sep 16, 2005, 2:23:52 PM9/16/05
to

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

0 new messages