Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Conversion from double to string (from newbie)

Reply
Thread Tools

Conversion from double to string (from newbie)

 
 
Marco Traverso
Guest
Posts: n/a
 
      12-06-2003
Hi all,
This may seem quite a basic question...
Is there a direct function to convert a double into a string? I'm used to
VBScript and it has the CStr function that does the job.

es. (vbScript)

Dim dN
Dim sString

dN =- Sqr(2)
sString = CStr(dN)

'sString returns "-1.4142135623731"

I've searched for a C / C++ function, and I found only the _ecvt
function (and other similar...).

Anyway they have slightly different input variables so the conversion is not
"automatic"

Is there a specific function or do I have to build my own?

Thank you in advance,

Marco


 
Reply With Quote
 
 
 
 
lallous
Guest
Posts: n/a
 
      12-06-2003
"Marco Traverso" <(E-Mail Removed)> wrote in message
news:mwnAb.9931$(E-Mail Removed)...
> Hi all,
> This may seem quite a basic question...
> Is there a direct function to convert a double into a string? I'm used to
> VBScript and it has the CStr function that does the job.
>
> es. (vbScript)
>
> Dim dN
> Dim sString
>
> dN =- Sqr(2)
> sString = CStr(dN)
>
> 'sString returns "-1.4142135623731"
>
> I've searched for a C / C++ function, and I found only the _ecvt
> function (and other similar...).
>
> Anyway they have slightly different input variables so the conversion is

not
> "automatic"
>
> Is there a specific function or do I have to build my own?
>
> Thank you in advance,
>
> Marco
>
>
>

Hello,

Checkout the sprintf() function.

--
Elias


 
Reply With Quote
 
 
 
 
Marco Traverso
Guest
Posts: n/a
 
      12-06-2003
Thank you Elias!

Marco

"lallous" <(E-Mail Removed)> ha scritto nel messaggio
news:bqt2n2$uaf37$(E-Mail Removed)-berlin.de...
> "Marco Traverso" <(E-Mail Removed)> wrote in message
> news:mwnAb.9931$(E-Mail Removed)...
> > Hi all,
> > This may seem quite a basic question...
> > Is there a direct function to convert a double into a string? I'm used

to
> > VBScript and it has the CStr function that does the job.
> >
> > es. (vbScript)
> >
> > Dim dN
> > Dim sString
> >
> > dN =- Sqr(2)
> > sString = CStr(dN)
> >
> > 'sString returns "-1.4142135623731"
> >
> > I've searched for a C / C++ function, and I found only the _ecvt
> > function (and other similar...).
> >
> > Anyway they have slightly different input variables so the conversion is

> not
> > "automatic"
> >
> > Is there a specific function or do I have to build my own?
> >
> > Thank you in advance,
> >
> > Marco
> >
> >
> >

> Hello,
>
> Checkout the sprintf() function.
>
> --
> Elias
>
>



 
Reply With Quote
 
Thierry Miceli
Guest
Posts: n/a
 
      12-06-2003
> Is there a direct function to convert a double into a string?
You can use string streams to do so:

#include <sstream>

std:stringstream ostr;

double d = 123.456;
ostr << d;
cout << ostr.str();


Thierry


 
Reply With Quote
 
Jon Bell
Guest
Posts: n/a
 
      12-06-2003
In article <mwnAb.9931$(E-Mail Removed)>,
Marco Traverso <(E-Mail Removed)> wrote:
>
>This may seem quite a basic question...


Yes, in fact it's in the FAQ.

>Is there a direct function to convert a double into a string?


There is no standard function to convert a double into a variable of the
standard 'string' data type, but you can easily write one to do so. See

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

--
Jon Bell <(E-Mail Removed)> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
 
Reply With Quote
 
Marco Traverso
Guest
Posts: n/a
 
      12-07-2003
Thank you all for your replies!
I didn't know about the FAQ, so the next time I'll search through them
before posting!

Thanx again,

Marco


"Jon Bell" <(E-Mail Removed)> ha scritto nel messaggio
news:bqt47p$5bk$(E-Mail Removed)...
> In article <mwnAb.9931$(E-Mail Removed)>,
> Marco Traverso <(E-Mail Removed)> wrote:
> >
> >This may seem quite a basic question...

>
> Yes, in fact it's in the FAQ.
>
> >Is there a direct function to convert a double into a string?

>
> There is no standard function to convert a double into a variable of the
> standard 'string' data type, but you can easily write one to do so. See
>
>

<http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-38.1>
>
> --
> Jon Bell <(E-Mail Removed)> Presbyterian College
> Dept. of Physics and Computer Science Clinton, South Carolina USA



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
conversion double* to vector<double> and vice versa J.M. C++ 5 03-08-2007 03:45 PM
replace double inverted commas into slash double inverted commas in string AviraM Java 2 09-28-2006 06:19 PM
cannot convert parameter from 'double (double)' to 'double (__cdecl *)(double)' error Sydex C++ 12 02-17-2005 06:30 PM
String to int/double conversion and parsing kaede C++ 1 09-04-2004 12:36 AM
Double -> C-String conversion Der Andere C++ 16 04-27-2004 02:31 PM



Advertisments