Standard C++ Library Reference ISO/IEC (VERSION3)
Next
Formatted Output
Print Formats · Print Functions · Print Conversion Specifiers
Several library functions help you convert data values from encoded internal representations to
text sequences that are generally readable by people. You provide a format string as the value of
the format argument to each of these functions, hence the term formatted output. The
functions fall into two categories.
The byte print functions (declared in <stdio.h>) convert internal representations to
sequences of type char, and help you compose such sequences for display: fprintf, printf,
sprintf, vfprintf, vprintf, and vsprintf. For these function, a format string is a multibyte string
that begins and ends in the initial shift state.
The wide print functions (declared in <wchar.h> and hence added with Amendment 1)
convert internal representations to sequences of type wchar_t, and help you compose such
sequences for display: fwprintf, swprintf, wprintf, vfwprintf, vswprintf, and vwprintf. For these
functions, a format string is a wide-character string. In the descriptions that follow, a wide
character wc from a format string or a stream is compared to a specific (byte) character c as if
by evaluating the expression wctob(wc) == c.
Print Formats
A format string has the same syntax for both the print functions and the scan functions, as
shown in the diagram.
A format string consists of zero or more conversion specifications interspersed with literal text
and white space. White space is a sequence of one or more characters c for which the call
isspace(c) returns nonzero. (The characters defined as white space can change when you
change the LC_CTYPE locale category.) For the print functions, a conversion specification is