Iostream Input and Output controllers in C ++

Source: Internet
Author: User

The input and output streams are defined in <iostream>, and the standard console output stream cout is also declared in this header file.

Header files containing control operators: Standard Header files <IOS> and <iomanip>

 

Output stream:

Boolalpha and noboolalpha: the notification output stream outputs bool to true and false (boolalpha) or 1 and 0 (noboolalpha ). The default value is noboolalpha.

Hex, Oct, and DEC: numbers are output in hexadecimal, octal, and 10hexadecimal respectively.

Setprecision: set the number of decimal places after the decimal point ). For example, setprecision (5) -- 5 digits after the decimal point.

SETW: Set the field width when the value is output. E.g. SETW (5 ).

Setfill: When the numeric width is less than the specified width, the control operator can specify characters for filling space. Setfill ('A ').

Showpoint and nonshowpoint: For floating-point numbers or double-precision numbers without decimals, this control operator forces the stream to always show decimal or decimal places.

Endl: encapsulate data and behavior. The number of notification streams outputs a carriage return and refreshes the output buffer.

The preceding control operators are written before the output parameters to be applied, such as cout <SETW (7) <setfill ('&') <variable <Endl;

E.g. # include <iostream>

# Include <iomanip>

Using namespace STD;

Int main (INT argc, char ** argv)

{

Bool testb = true;

Cout <"this is a testing of bool" <boolalpha <testb <Endl;

}

 

Input stream:

Boolalpha and noboolalpha: the true and false strings are interpreted as Boolean true and false for input and storage (boolalpha ). Noboolalpha does not explain this way. The default value is noboolalpha.

Hex, Oct, and DEC: numbers are read in hexadecimal, octal, and 10hexadecimal respectively.

Skipwa and noskipwa: When a notification stream performs lexical analysis, it ignores the blank space or reads the blank space as the token of a blank space.

WS: traverses the control operator. Ignore a blank string in the current position of the stream.

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.