C++/C string Formatting

Source: Internet
Author: User

percent-Returns
%b– return binary number
%c– returns the character corresponding to the ASCII value
%d– decimal number with plus sign
%e– Scientific counting symbols (e.g.: 1.2e+2)
%u– the unsigned decimal number.%ul Long integer without symbol
%f– Floating-point data (local setting)
%f– Floating-point data (non-local settings)
%o– octal number
%s– String
%x– hexadecimal number (lowercase letters) for example: sprintf (S, "% #010x", 128);//Generate "0x00000080"

%x– hexadecimal number (capital letter)


If the% is followed by numbers, such as:%2f,%2.3f these,%M.N and so on, the M in front of the decimal point represents the number of digits of the entire number,

n indicates how many bits are in the decimal point:

Double A = 326.3845;printf ("%10.3f\n", a);
The result is:

326.385 (Note that there is a space in front)

This shows that the rounding method is taken here.

If there are characters in front of M, then the spaces preceding the above results are complete with that character:


printf ("%04d", 3);
The result is:

0003




C++/C string Formatting

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.