Standard C++ Library Reference ISO/IEC (VERSION3)
(which must be of type int) as the field width. If the argument value is negative, it supplies a -
format flag and its magnitude is the field width.
Following any field width, you can write a dot (.) followed by a precision that specifies one of
the following: the minimum number of digits to generate on an integer conversion; the number
of fraction digits to generate on an e, E, or f conversion; the maximum number of significant
digits to generate on a g or G conversion; or the maximum number of characters to generate
from a C string on an s conversion.
If you write an * instead of a decimal number for a precision, a print function takes the value of
the next argument (which must be of type int) as the precision. If the argument value is
negative, the default precision applies. If you do not write either an * or a decimal number
following the dot, the precision is zero.
Print Conversion Specifiers
Following any precision, you must write a one-character print conversion specifier, possibly
preceded by a one- or two-character qualifier. Each combination determines the type required of
the next argument (if any) and how the library functions alter the argument value before
converting it to a text sequence. The integer and floating-point conversions also determine what
base to use for the text representation. If a conversion specifier requires a precision p and you
do not provide one in the format, then the conversion specifier chooses a default value for the
precision. The following table lists all defined combinations and their properties.
Conversion Argument Converted Default Pre-
Specifier Type Value Base cision
%c int x (unsigned char)x
%lc wint_t x wchar_t a[2] = {x}
%d int x (int)x 10 1
%hd int x (short)x 10 1
%ld long x (long)x 10 1
%e double x (double)x 10 6
%Le long double x (long double)x 10 6
%E double x (double)x 10 6
%LE long double x (long double)x 10 6
%f double x (double)x 10 6
%Lf long double x (long double)x 10 6
%g double x (double)x 10 6
%Lg long double x (long double)x 10 6