Standard Input/Output library iostream of C ++

Source: Internet
Author: User
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"
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.