C language can use printf (),%f to achieve the format of floating point number output, with cout ...?
The Iomanip is the I/O flow control header file, just like the formatted output of printf.
Here are some common ones:
Dec base is 10 equivalent to "%d"
Hex base is 16 equivalent to "%x"
The OCT has a base of 8 equivalent to "%o"
Setfill (c) Set the fill character to C
Setprecision (n) Set display decimal precision is n bit
SETW (n) Set a field width of n characters
Setioflags (ios::fixed) fixed floating-point display
Setioflags (ios::scientific) index indicates
Setiosflags (ios::left) Align Left
Setiosflags (ios::right) Align Right
Setiosflags (IOS::SKIPWS ignores leading whitespace
Setiosflags (ios::uppercase) 16 Decimal Capital Output
Setiosflags (ios::lowercase) 16 binary lowercase output
Setiosflags (ios::showpoint) force display decimal point
Setiosflags (ios::showpos) force display symbols
1#include <iostream>2#include <iomanip>3 using namespacestd;4 DoubleD=11.23456;5 intMain ()6 {7cout<<d<<endl;//Direct output can only output 6 digits, including integer and fractional parts8Cout<<setprecision (3) <<d<<endl;//accuracy of 3, output 3-digit9Cout<<setiosflags (iOS::fixed) <<d<<endl;//Precision 3, fixed-point output, 3-bit fractional outputTenCout<<setiosflags (iOS::fixed) <<setprecision (7) <<d<<endl;//the number of digits is not enough, add 0 at the end One return 0; A}
C + + cout formatted output method