Professional Documents
Culture Documents
Stream Manipulators
I/O stream manipulators modify the behavior of insertions (<<) and extractions (>>). Examples:
endl, flush oct, dec, hex (persistent effect: a change stays effective until another change is requested)
// 10 20 // 12 24 // a 14 10
int i = 10; cout << i << << i + i << endl; cout << oct << i << << i + i << endl; cout << hex << i << << i + i << << dec << i << endl;
Number Systems
Octal
Base 8 8 symbols Base 16 16 symbols More compact representation of the binary system
Hexadecimal
setprecision(d) - set number of significant digits to d (d = 0 for default precision); enforce d decimal places by setting the I/O flag fixed setw(w) - set field width to w (or minimally larger than w to display the value correctly) setfill(c) - set fill character to c setiosflags(f) - set flag f to 1 resetiosflags(f) - set flag f to 0
ios::fixed
Fixed-point notation (default: not set) Example: 12.34
ios::scientific
Floating-point notation (default: not set) Example: 1.234e+001
ios::showpoint
Decimal point and trailing 0s (default: not set) Example: 12.00
ios::showpos
A plus (+) sign is shown before positive numbers (default: not set) Example: +12
ios::right
Right-justified format when used with setw() (default: set) Left-justified format when used with setw() (default: not set)
ios::left