[C ++ Note] use a controller in the input stream and output stream

Source: Internet
Author: User

If you want to use a controller in a program, you must add the iomanip header file in addition to the iostream header file at the beginning of the file.

Role of a controller

Dec sets the base number of the value to 10.

Hex sets the base number of a value to 16.

Oct sets the base number of the value to 8.

Setfill (c) sets the padding character of the next output to C, and C can be a character constant or a character variable.

 

Setprecision (n) sets the floating point precision to N bits. N represents a valid number when output in decimal form. When output in the fixed (fixed decimal scale) form and scientific (exponential) form, n is the decimal point

SETW (n) sets the field width of the next output to N bits (equivalent to the form of printf ("% 5d", n) in C)

Setiosflags (IOs: fixed) is used to set the floating point to display at a fixed number of decimal places.

Setiosflags (IOs: Scientific) is used to set floating point numbers to be displayed in scientific notation (exponential form ).

Setiosflags (IOs: Left) Left-aligned output data

Setiosflags (IOs: Right) Right-aligned output data

Setiosflags (IOs: skipws) ignores leading Spaces

Setiosflags (IOs: uppercase) data is output in hexadecimal notation with uppercase letters (lower case letters by default)

Setiosflags (ios: lowercase) data is output in hexadecimal notation with lowercase letters

Setiosflags (ios: showpos) returns the "+" when a positive number is output.

 

Except setfill () and setw (), the output is valid after these options are set. Setfill () and setw () are only valid for the subsequent output.

[Question] It seems that dec, hex, and oct are invalid for floating point numbers. Which prawns can explain?

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.