Thanks Victor!!!
It works perfectly... and I've learned a lot about cout (I'm at the begin
of the book :)
the manipulator are at pag.726 ;) ;)
Thanks to Chris, too
Evenif it was not a solution for my problem (I'm sorry but my english is
terrible and it's very easy to misunderstand me) I've learned from you
about template.
Greetings from Italy ;)
Checco.
On Tue, 29 Jul 2003 14:53:35 -0400, Victor Bazarov <v.********@attAbi.com>
wrote:
"Francesco" <ch***********@tin.it> wrote... [...]
sprintf(buff,"%3.15f", 1.572757843657862662);
[...]
stringstream buff;
string risultato;
buff << 12.34324435;
buff >> risultato;
These two are definitely not the same. Try losing those numbers in
the format string in 'sprintf' (use "%f" instead of "%3.15f") and
see what happens.
-----------------------------------------------------
but I lose several decimal digits....
You don't lose anything. Instead, with 'sprintf' you _specifically_
_gain_ more digits by using the precision (that "15" after the dot).
By the way, several people say it's not good C++ programming to use C
code
(for example the Stroustrup's book), but I think it's useful to use
sprintf!!
Nobody is going to tell you what to think. Think whatever you please.
May somebody tell me if exist a C++ function that works like sprintf and
I've missed???
No, there is no "C++ function that works like sprintf". However, if
you want to control how many digits are output to 'cout', see the
description of "I/O manipulators" in your favourite book. Learn about
the available functionality instead of substituting it with something
you already know. Key words here are "setprecision", "setw", "fixed".
What do you think about to use C code inside C++???
I think it is unnecessary.
Victor