A detailed description of C + + formatted output functions

Source: Internet
Author: User

The Iomanip is the I/O flow control header file, just like the formatted output in C. Here are some common: the DEC base is 10 equivalent to "%d" hex base 16 equivalent to "%x" Oct base 8 equivalent to "%o" Setfill (c) Set the fill character to Csetprecision (n) to display a decimal precision of n bits SETW (n) Set the field width to n characters setioflags (ios::fixed) fixed floating point display setioflags (ios::scientific) The exponent represents the Setiosflags (Ios::left) left-aligned setiosflags (ios::right) right-aligned setiosflags (IOS::SKIPWS ignores leading whitespace setiosflags (ios::uppercase ) 16 Decimal Capital Output setiosflags (ios::lowercase) 16 lowercase output setiosflags (ios::showpoint) force display of decimals Setiosflags (ios::showpos) force display symbols

Required header file:

#include <iostream> #include <iomanip>

function of SETW (n): Preset width

COUT<<SETW (6) <<12345<<endl;

Setfill (char c): If there is no unused width in the preset width, use the Set character C to fill

Cout<<setfill (' # ') <<SETW (6) <<12345<<endl;

Role of SetBase (n): Converting output data to N-binary

Cout<<setbase (2) <<255<<endl;  Cout<<setbase (8) <<255<<endl; Cout<<setbase (<<255<<endl;)

Setprecision (): Controls the output stream to display the number of floating-point numbers. C + + default stream output numeric value bit is 6

If Setprecision (n) is combined with setiosflags (ios::fixed), you can control the number of digits to the right of the decimal point.    Setiosflags (ios::fixed) is a fixed-point representation of real numbers. If combined with setiosflags (ios::scientific), you can control the number of decimal digits of exponential notation. Setiosflags (ios::scientific) is an exponential representation of real numbers.

Cout<<setiosflags (ios::fixed) <<setprecision (8) <<25.376<<endl;

In the output with floating-point representation, Setprecision (n) represents the number of significant digits.


A detailed description of C + + formatted output functions

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.