J
jacek.dziedzic
Hello!
Can someone tell me what the expected output of the following
program is?
#include <fstream>
#include <iomanip>
using namespace std;
int main() {
ofstream o("o");
o << fixed << setprecision(0) << 13.0 << endl;
}
Depending on which STL implementation I use with my compiler, I
either get
"13" or "13.000000".
I don't have the Standard (at all) or the Josuttis book (with me),
so can anyone
shed some light on what setprecision(0) does? I seem to vaguely recall
that it
turns precision control off (13.000000 would be the 'right' output
then), but I'm
not sure (or is it setprecision(-1)?).
Moreover, I'm after option 1, that is, I insist on printing my
doubles with _no_
digits past the decimal point (and no decimal point), how do I achieve
this
behaviour? The obvious solution "convert to int and output" is not
available to me.
I only have the ofstream object, the output is done by some class's
operator<<,
which outputs a series of doubles and which I cannot modify. Up to now
I could
control everything with setprecision() and a method set_maths_width()
that the
class provides (as setw() works for the first output only), but when I
want a
precision of 0... I'm stumped.
TIA,
- J.
Can someone tell me what the expected output of the following
program is?
#include <fstream>
#include <iomanip>
using namespace std;
int main() {
ofstream o("o");
o << fixed << setprecision(0) << 13.0 << endl;
}
Depending on which STL implementation I use with my compiler, I
either get
"13" or "13.000000".
I don't have the Standard (at all) or the Josuttis book (with me),
so can anyone
shed some light on what setprecision(0) does? I seem to vaguely recall
that it
turns precision control off (13.000000 would be the 'right' output
then), but I'm
not sure (or is it setprecision(-1)?).
Moreover, I'm after option 1, that is, I insist on printing my
doubles with _no_
digits past the decimal point (and no decimal point), how do I achieve
this
behaviour? The obvious solution "convert to int and output" is not
available to me.
I only have the ofstream object, the output is done by some class's
operator<<,
which outputs a series of doubles and which I cannot modify. Up to now
I could
control everything with setprecision() and a method set_maths_width()
that the
class provides (as setw() works for the first output only), but when I
want a
precision of 0... I'm stumped.
TIA,
- J.