You are on page 1of 2

fixed - write floating-point values in fixed-point notation

left - the output is padded to the field width appending fill characters at the end.
right - the output is padded to the field width by inserting fill characters at the
beginning.
setprecision - Sets the decimal precision to be used to format floating-point values on
output operations.
The left function is able to pad the output to the field width by appending fill
characters at the end.
The right function is able to pad the output to the field width by inserting fill
characters at the end.
Example given:
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
int n=230;
cout.width(8); cout left n "a" endl;
cout.width(8); cout "a" right n endl;
system("pause");
return 0;
}
Output:
230 a
230
In this example, the left function happens on line 7, at which the output would show
up as '230 a', as the field width is 8, and the integer is 3 numbers long, 5 spaces of
fill characters is appended after '230' to fill up the field width.
And the right function happens on line 8, where the output is ' 230', as the field
width is 8, and the integer is 3 numbers long, 5 spaces of fill characters is inserted

before '230' to fill up the field width.

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double pharz = 12.0795;

cout << showpoint << setprecision(4);


cout << pharz << endl;

cout << showpoint << setprecision(5);


cout << pharz << endl;

cout << fixed << showpoint << setprecision(3);


cout << pharz << endl;

cout << fixed << showpoint << setprecision(4);


cout << pharz << endl;

system("pause");

return 0;

You might also like