Standard I/O Stream
Standard Input/Output library iostream of C ++
It not only provides an I/O library, but also provides a stream mode for using the library.
"Cin>" inbound and "cout <" operator that flows out to the output device
1. Stream status)
1 st showpos is displayed + before positive (including 0)
2nd showbase HEX plus 0X, OCT plus 0
Uppercase letters in 3rd uppercase HEX
4th showpoint Floating Point Output adds a decimal point even if it is 0 after the decimal point
The logical value of 5th boolalpha is true and false.
6 th left alignment
7th right
8 th dec decimal integer
9th hex hexadecimal
10 oct octal
11 fixed point format output
12 scientific Note format output
2. Cancel the stream status operation
Noshowpos noshowbase nouppercase noshowpoint noboolalpha
Cout. unsetf (ios: scientific );
3. Three Common stream states with Parameters
Width (int) // you can specify the display width.
Fill (char) // sets the padding character
Precision (int) // sets the valid digits.
These stream statuses are set in the form of cout bundling and cannot be used with the outbound operator <
Note that width (n) is a one-time operation. The default width (0) is no longer valid for the second display)
Example
Cout. width (5 );
Cout. fill ('s ');
Cout <23 <23;
// SSS2323
4. configuration method used with <
The header file iomanip must be included.
Setw (int)
Setfill (char)
Setprecision (int)
Example
Cout <setw (6) <setfill ('$') <endl; // output: $27
Inverted triangle example
# Include <iostream>
# Include <iomanip>
Using namespace std;
Void main ()
{
For (int n = 1; n <= 10; ++ n)
Cout <setfill ('') <setw (n) <""
<Setfill ('M') <setw (21-2 * n) <"M" <endl;
}
Also use string
# Include <iostream>
# Include <string>
Using namespace std;
Int main ()
{
For (int n = 1; n <= 10; ++ n)
Cout <string (n, '') + string (21-2 * n, 'M') +"/n"
}