The necessity of 'showpoint' manipulator
Posted: Sat Aug 10, 2013 12:35 pm
Hi,
I am a novice on C++ programming, and recently I am studying decimal representations.
Eventually I found the following code:
And the output is, 0.0000.
I found that the purpose of 'showpoint' is to display the decimal point if it is a floating-point number, no matter the decimal part exists or not.
However, the 'fixed' manipulator does the same thing (apparently for me).
And the output for this code segment is also 1.0000.
Is 'showpoint' necessary in the above code?
What are the differences between these codes?
Many thanks,
Samuel
I am a novice on C++ programming, and recently I am studying decimal representations.
Eventually I found the following code:
Code: Select all
#include<iostream>
#include<iomanip>
using namespace std;
int main(void){
float x = 1;
cout << fixed << showpoint << setprecision(4);
cout << x;
return 0;
}
I found that the purpose of 'showpoint' is to display the decimal point if it is a floating-point number, no matter the decimal part exists or not.
However, the 'fixed' manipulator does the same thing (apparently for me).
Code: Select all
#include<iostream>
#include<iomanip>
using namespace std;
int main(void){
float x = 1;
cout << fixed << setprecision(4);
cout << x;
return 0;
}
Is 'showpoint' necessary in the above code?
What are the differences between these codes?
Many thanks,
Samuel