Professional Documents
Culture Documents
2nd format:
The arg1 is one of the formatting flags defined in the class ios. The arg2 known as bit field
specifies the group to which the formatting flag belongs.
1st argument should be one of the group members of the second argument.
The flags set by setf() remain effective until they are reset or unset. It can be reset any number of
times in a program. We can apply more than one format controls jointly on an output value. The
setf() sets the specified flags and leaves others unchanged. i.e. these flags are mutually exclusive
and therefore can be set or cleared independently.
Examples:
cout.fill(‘~’);
cout.setf(ios::left,ios::adjustfield);
cout.width(10);
cout << “VALUE”; gives output:VALUE~~~~~
General Form:
cout << manip1 << manip2 << manip3 << variable;
cout << manip1 << variable1 << manip2 << variable2;
Manipulator Equivalent
setw(int w) width()
setprecision(int d) precision()
setfill(int c) fill()
setiosflags(long f) setf()
resetiosflags(long f) unsetf()
endl “\n”
Examples:
cout << setw(10) << 12345;
cout << setw(10) << setiosflags(ios::left) << 12345;
cout << setw(5) << setprecision(2) << 1.2345 << setw(10) << setprecision(4) << sqrt(2) << endl;