I understand what the fixed
and showpoint
manipulators do on their own, but why would you want to use them both at the same time? This is what DS Malik's C++ Programming textbook says:
Of course, the following statement sets the output of a floating-point number in a fixed decimal format with the decimal point and trailing zeros on the standard output device:
cout << fixed << showpoint;
But doesn't fixed
alone set the output to be "fixed decimal format with the decimal point and trailing zeros"?
I tried running my own experiment:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
cout << setprecision(3);
cout << "only fixed" << "\t" << "fixed + showpoint" << endl;
for (double i = 0.000001; i <= 100000; i *= 10) {
cout << fixed << i << "\t\t";
cout << showpoint << i << endl;
cout.unsetf(ios::fixed);
cout.unsetf(ios::showpoint);
}
}
But I fail to see the difference between using only fixed
and using fixed
and showpoint
together, in that order:
only fixed fixed + showpoint
0.000 0.000
0.000 0.000
0.000 0.000
0.001 0.001
0.010 0.010
0.100 0.100
1.000 1.000
10.000 10.000
100.000 100.000
1000.000 1000.000
10000.000 10000.000
100000.000 100000.000
Any insight would be greatly appreciated!