Standard C++ Library Reference ISO/IEC (VERSION3)

Next
Formatted Input
Scan Formats · Scan Functions · Scan Conversion Specifiers
Several library functions help you convert data values from text sequences that are generally
readable by people to encoded internal representations. You provide a format string as the value
of the format argument to each of these functions, hence the term formatted input. The
functions fall into two categories:
The byte scan functions (declared in <stdio.h>) convert sequences of type char to internal
representations, and help you scan such sequences that you read: fscanf, scanf, and sscanf. For
these function, a format string is a multibyte string that begins and ends in the initial shift state.
The wide scan functions (declared in <wchar.h> and hence added with Amendment 1)
convert sequences of type wchar_t, to internal representations, and help you scan such
sequences that you read: fwscanf, wscanf, and swscanf. 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.
Scan Formats
A format string has the same general syntax for the scan functions as for the print functions:
zero or more conversion specifications, interspersed with literal text and white space. For the
scan functions, however, a conversion specification is one of the scan conversion specifications
described below.
A scan function scans the format string once from beginning to end to determine what
conversions to perform. Every scan function accepts a varying number of arguments, either
directly or under control of an argument of type va_list. Some scan conversion
specifications in the format string use the next argument in the list. A scan function uses each
successive argument no more than once. Trailing arguments can be left unused.
In the description that follows, the integer conversions and floating-point conversions are the
same as for the print functions.