R. Clayton (rclayton@clayton.cs.monmouth.edu)
(no date)
How can I can convert a double type to a string?
Converting floating point numbers to strings is a real pain in c++; I'd think
carefully about solving the fourth assignment with floating point numbers.
But, if you want to go that way, you should look at the <stringstream> (not
<strstream>) class (uncovered in Dietel and Dietel) and the stream manipulators
(Section 11.6 in Dietel and Dietel).
I was thinking of using fcvt() or fspringf(), but I don't think these
functions will come out the way I need to do correct convertion.
I don't understand your requirements, but if I were to solve the fourth
assignment using floating-point numbers, I'd use snprintf() (not sprintf()),
which is part of standard C (<stdio.h>), and so part of standard c++
(<cstdio>).
I have been trying to write my own function for double to string convertion,
but for some reason, the digit after the decimal does not come out as I
expected.
I wouldn't recommend doing that even as an exercise.
This archive was generated by hypermail 2.0b3 on Mon Dec 17 2001 - 19:30:04 EST