Skip to content

Latest commit

 

History

History
78 lines (63 loc) · 8.35 KB

vprintf-functions.md

File metadata and controls

78 lines (63 loc) · 8.35 KB
titledescriptionms.datehelpviewer_keywords
vprintf Functions
Learn more about: vprintf Functions
11/04/2016
vprintf functions
formatted text [C++]

vprintf functions

Each of the vprintf functions takes a pointer to an argument list, then formats and writes the given data to a particular destination. The functions differ in several ways: in the parameter validation, whether the functions take single-byte or wide character strings, the output destination, and the support for specifying the order parameters are used in the format string.

_vcprintf, _vcwprintf
vfprintf, vfwprintf
_vfprintf_p, _vfprintf_p_l, _vfwprintf_p, _vfwprintf_p_l
vfprintf_s, _vfprintf_s_l, vfwprintf_s, _vfwprintf_s_l
vprintf, vwprintf
_vprintf_p, _vprintf_p_l, _vwprintf_p, _vwprintf_p_l
vprintf_s, _vprintf_s_l, vwprintf_s, _vwprintf_s_l
_vscprintf, _vscprintf_l, _vscwprintf, _vscwprintf_l
_vsnprintf, _vsnwprintf
vsprintf, vswprintf
_vsprintf_p, _vsprintf_p_l, _vswprintf_p, _vswprintf_p_l
vsprintf_s, _vsprintf_s_l, vswprintf_s, _vswprintf_s_l

Remarks

The vprintf functions are similar to their counterpart functions as listed in the following table. However, each vprintf function accepts a pointer to an argument list, whereas each of the counterpart functions accepts an argument list.

These functions format data for output to destinations as follows.

FunctionCounterpart functionOutput destinationParameter ValidationPositional Parameter Support
_vcprintf_cprintfconsoleCheck for null.no
_vcwprintf_cwprintfconsoleCheck for null.no
vfprintffprintfstreamCheck for null.no
vfprintf_pfprintf_pstreamCheck for null and valid format.yes
vfprintf_sfprintf_sstreamCheck for null and valid format.no
vfwprintffwprintfstreamCheck for null.no
vfwprintf_pfwprintf_pstreamCheck for null and valid format.yes
vfwprintf_sfwprintf_sstreamCheck for null and valid format.no
vprintfprintfstdoutCheck for null.no
vprintf_pprintf_pstdoutCheck for null and valid format.yes
vprintf_sprintf_sstdoutCheck for null and valid format.no
vwprintfwprintfstdoutCheck for null.no
vwprintf_pwprintf_pstdoutCheck for null and valid format.yes
vwprintf_swprintf_sstdoutCheck for null and valid format.no
vsprintfsprintfmemory pointed to by bufferCheck for null.no
vsprintf_psprintf_pmemory pointed to by bufferCheck for null and valid format.yes
vsprintf_ssprintf_smemory pointed to by bufferCheck for null and valid format.no
vswprintfswprintfmemory pointed to by bufferCheck for null.no
vswprintf_pswprintf_pmemory pointed to by bufferCheck for null and valid format.yes
vswprintf_sswprintf_smemory pointed to by bufferCheck for null and valid format.no
_vscprintf_vscprintfmemory pointed to by bufferCheck for null.no
_vscwprintf_vscwprintfmemory pointed to by bufferCheck for null.no
_vsnprintf_snprintfmemory pointed to by bufferCheck for null.no
_vsnwprintf_snwprintfmemory pointed to by bufferCheck for null.no

The argptr argument has type va_list, which is defined in VARARGS.H and STDARG.H. The argptr variable must be initialized by va_start, and may be reinitialized by subsequent va_arg calls; argptr then points to the beginning of a list of arguments that are converted and transmitted for output according to the corresponding specifications in the format argument. format has the same form and function as the format argument for printf. None of these functions invoke va_end. For a more complete description of each vprintf function, see the description of its counterpart function as listed in the preceding table.

_vsnprintf differs from vsprintf in that it writes no more than count bytes to buffer.

The versions of these functions with the w infix in the name are wide-character versions of the corresponding functions without the w infix; in each of these wide-character functions, buffer and format are wide-character strings. Otherwise, each wide-character function behaves identically to its SBCS counterpart function.

The versions of these functions with _s and _p suffixes are the more secure versions. These versions validate the format strings. They'll generate an exception if the format string isn't well formed (for example, if invalid formatting characters are used).

The versions of these functions with the _p suffix let you specify the order in which the supplied arguments are substituted in the format string. For more information, see printf_p Positional Parameters.

For vsprintf, vswprintf, _vsnprintf and _vsnwprintf, if copying occurs between strings that overlap, the behavior is undefined.

Important

Ensure that format is not a user-defined string. For more information, see Avoiding buffer overruns. If using the secure versions of these functions (either the _s or _p suffixes), a user-supplied format string could trigger an invalid parameter exception if the user-supplied string contains invalid formatting characters.

See also

Stream I/O
fprintf, _fprintf_l, fwprintf, _fwprintf_l
printf, _printf_l, wprintf, _wprintf_l
sprintf, _sprintf_l, swprintf, _swprintf_l, __swprintf_l
va_arg, va_copy, va_end, va_start

close