For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.
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 the parameter validation performed, whether the functions take wide or single-byte character strings, the output destination, and the support for specifying the order in which parameters are used in the format string.
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.
|Function||Counterpart function||Output destination||Parameter Validation||Positional Parameter Support|
|_cprintf||console||Check for null.||no|
|_cwprintf||console||Check for null.||no|
|fprintf||Stream||Check for null.||no|
|vfprintf_p||fprintf_p||Stream||Check for null and valid format.||yes|
|fprintf_s||Stream||Check for null and valid format.||no|
|fwprintf||Stream||Check for null.||no|
|vfwprintf_p||fwprintf_p||Stream||Check for null and valid format.||yes|
|fwprintf_s||Stream||Check for null and valid format.||no|
|printf||Check for null.||no|
|vprintf_p||printf_p||Check for null and valid format.||yes|
|printf_s||Check for null and valid format.||no|
|wprintf||Check for null.||no|
|vwprintf_p||wprintf_p||Check for null and valid format.||yes|
|wprintf_s||Check for null and valid format.||no|
|vsprintf||sprintf||memory pointed to by buffer||Check for null.||no|
|vsprintf_p||sprintf_p||memory pointed to by buffer||Check for null and valid format.||yes|
|sprintf_s||memory pointed to by buffer||Check for null and valid format.||no|
|swprintf||memory pointed to by buffer||Check for null.||no|
|vswprintf_p||swprintf_p||memory pointed to by buffer||Check for null and valid format.||yes|
|swprintf_s||memory pointed to by buffer||Check for null and valid format.||no|
|_vscprintf||memory pointed to by buffer||Check for null.||no|
|_vscwprintf||memory pointed to by buffer||Check for null.||no|
|_snprintf||memory pointed to by buffer||Check for null.||no|
|_snwprintf||memory pointed to by buffer||Check for null.||no|
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
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 invokes
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 and will generate an exception if the format string is not well formed (for example, if invalid formatting characters are used).
The versions of these functions with the _p suffix provide the ability to specify the order in which the supplied arguments are substituted in the format string. For more information, see printf_p Positional Parameters.
_vsnwprintf, if copying occurs between strings that overlap, the behavior is undefined.
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.