The necessity of 'showpoint' manipulator

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
SamuelTangz
New poster
Posts: 4
Joined: Wed Jul 31, 2013 11:09 am

The necessity of 'showpoint' manipulator

Post by SamuelTangz »

Hi,

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;
}
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).

Code: Select all

#include<iostream>
#include<iomanip>
using namespace std;
int main(void){
 float x = 1;
 cout << fixed << setprecision(4);
 cout << x;
 return 0;
}
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
Post Reply

Return to “C++”