vprintf、_vprintf_l、vwprintf、_vwprintf_lvprintf, _vprintf_l, vwprintf, _vwprintf_l

使用指向参数列表的指针编写格式化输出。Writes formatted output by using a pointer to a list of arguments. 提供这些函数的更多安全版本;请参阅 vprintf_s、_vprintf_s_l、vwprintf_s、_vwprintf_s_lMore secure versions of these functions are available, see vprintf_s, _vprintf_s_l, vwprintf_s, _vwprintf_s_l.

语法Syntax

int vprintf(
   const char *format,
   va_list argptr
);
int _vprintf_l(
   const char *format,
   locale_t locale,
   va_list argptr
);
int vwprintf(
   const wchar_t *format,
   va_list argptr
);
int _vwprintf_l(
   const wchar_t *format,
   locale_t locale,
   va_list argptr
);

参数Parameters

formatformat
格式规范。Format specification.

argptrargptr
指向参数列表的指针。Pointer to list of arguments.

localelocale
要使用的区域设置。The locale to use.

有关更多信息,请参见 格式规范For more information, see Format Specifications.

返回值Return Value

vprintfvwprintf返回写入的字符数,不包括终止 null 字符,或在出现输出错误时返回一个负值。vprintf and vwprintf return the number of characters written, not including the terminating null character, or a negative value if an output error occurs. 如果format为空指针,或如果格式字符串包含无效的格式字符,则将调用无效的参数处理程序,如参数验证中所述。If format is a null pointer, or if the format string contains invalid formatting characters, the invalid parameter handler is invoked, as described in Parameter Validation. 如果允许执行继续,则函数将返回-1,并将errno设置为EINVALIf execution is allowed to continue, the functions return -1 and set errno to EINVAL.

有关这些代码及其他错误代码的信息,请参阅 _doserrno、errno、_sys_errlist 和 _sys_nerrFor information on these and other error codes, see _doserrno, errno, _sys_errlist, and _sys_nerr.

备注Remarks

其中每个函数都采用一个指向参数列表的指针,然后将给定数据格式化并写入stdoutEach of these functions takes a pointer to an argument list, then formats and writes the given data to stdout.

vwprintfvprintf的宽字符版本;如果在 ANSI 模式下打开流,则这两个函数的行为相同。vwprintf is the wide-character version of vprintf; the two functions behave identically if the stream is opened in ANSI mode. vprintf当前不支持输出到 UNICODE 流中。vprintf doesn't currently support output into a UNICODE stream.

这些带有 _l后缀的函数的版本相同,只不过它们使用传入的区域设置参数而不是当前线程区域设置。The versions of these functions with the _l suffix are identical except that they use the locale parameter passed in instead of the current thread locale.

重要

确保 format不是用户定义的字符串。Ensure that format is not a user-defined string. 有关详细信息,请参阅 避免缓冲区溢出For more information, see Avoiding Buffer Overruns. 请注意,已检测到无效格式字符串并发生错误。Note that invalid format strings are detected and result in an error.

一般文本例程映射Generic-Text Routine Mappings

TCHAR.H 例程TCHAR.H routine 未定义 _UNICODE 和 _MBCS_UNICODE & _MBCS not defined 已定义 _MBCS_MBCS defined 已定义 _UNICODE_UNICODE defined
_vtprintf_vtprintf vprintfvprintf vprintfvprintf vwprintfvwprintf
_vtprintf_l_vtprintf_l _vprintf_l_vprintf_l _vprintf_l_vprintf_l _vwprintf_l_vwprintf_l

要求Requirements

例程所返回的值Routine 必需的标头Required header 可选标头Optional headers
vprintf_vprintf_lvprintf, _vprintf_l <stdio.h> 和 <stdarg.h><stdio.h> and <stdarg.h> <varargs.h>*<varargs.h>*
vwprintf_vwprintf_lvwprintf, _vwprintf_l <stdio.h> 或 <wchar.h> 和 <stdarg.h><stdio.h> or <wchar.h>, and <stdarg.h> <varargs.h>*<varargs.h>*

* 仅对 UNIX V 兼容性是必需的。* Required for UNIX V compatibility.

通用 Windows 平台 (UWP) 应用中不支持控制台。The console is not supported in Universal Windows Platform (UWP) apps. 与控制台、 stdinstdoutstderr关联的标准流句柄必须重定向, 然后 C 运行时函数才能在 UWP 应用中使用它们。The standard stream handles that are associated with the console, stdin, stdout, and stderr, must be redirected before C run-time functions can use them in UWP apps. 有关其他兼容性信息,请参阅 兼容性For additional compatibility information, see Compatibility.

请参阅See also

流 I/OStream I/O
vprintf 函数vprintf Functions
fprintf、_fprintf_l、fwprintf、_fwprintf_lfprintf, _fprintf_l, fwprintf, _fwprintf_l
printf、_printf_l、wprintf、_wprintf_lprintf, _printf_l, wprintf, _wprintf_l
sprintf、_sprintf_l、swprintf、_swprintf_l、__swprintf_lsprintf, _sprintf_l, swprintf, _swprintf_l, __swprintf_l
va_arg、va_copy、va_end、va_startva_arg, va_copy, va_end, va_start