vfprintf_s、_vfprintf_s_l、vfwprintf_s、_vfwprintf_s_lvfprintf_s, _vfprintf_s_l, vfwprintf_s, _vfwprintf_s_l

使用指向参数列表的指针写入格式化的输出。Write formatted output using a pointer to a list of arguments. 这些版本的 vfprintf、_vfprintf_l、vfwprintf、_vfwprintf_l 具有安全增强功能,如 CRT 中的安全功能所述。These are versions of vfprintf, _vfprintf_l, vfwprintf, _vfwprintf_l with security enhancements as described in Security Features in the CRT.

语法Syntax

int vfprintf_s(
   FILE *stream,
   const char *format,
   va_list argptr
);
int _vfprintf_s_l(
   FILE *stream,
   const char *format,
   locale_t locale,
   va_list argptr
);
int vfwprintf_s(
   FILE *stream,
   const wchar_t *format,
   va_list argptr
);
int _vfwprintf_s_l(
   FILE *stream,
   const wchar_t *format,
   locale_t locale,
   va_list argptr
);

参数Parameters

stream
指向文件结构的指针。Pointer to FILE structure.

formatformat
格式规范。Format specification.

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

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

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

返回值Return Value

vfprintf_svfwprintf_s返回写入的字符,不包括终止 null 字符,则为负值,如果发生输出错误数。vfprintf_s and vfwprintf_s return the number of characters written, not including the terminating null character, or a negative value if an output error occurs. 如果任一格式是 null 指针,或如果格式字符串包含无效格式字符,将调用无效参数处理程序,如中所述参数验证If either stream or 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 并设置errnoEINVALIf 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

每个函数采用一个指向参数列表,然后格式化和写入到给定的数据Each of these functions takes a pointer to an argument list, then formats and writes the given data to stream.

这些函数与不安全版本差异仅在于安全版本检查格式字符串包含有效格式化字符。These functions differ from the non-secure versions only in that the secure versions check that the format string contains valid formatting characters.

vfwprintf_s是宽字符版本vfprintf_s; 如果在 ANSI 模式下打开流,则两个函数行为相同。vfwprintf_s is the wide-character version of vfprintf_s; the two functions behave identically if the stream is opened in ANSI mode. vfprintf_s当前不到 UNICODE 流支持输出。vfprintf_s 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.

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

TCHAR.H 例程TCHAR.H routine 未定义 _UNICODE 和 _MBCS_UNICODE & _MBCS not defined 已定义 _MBCS_MBCS defined 已定义 _UNICODE_UNICODE defined
_vftprintf_s_vftprintf_s vfprintf_svfprintf_s vfprintf_svfprintf_s vfwprintf_svfwprintf_s
_vftprintf_s_l_vftprintf_s_l _vfprintf_s_l_vfprintf_s_l _vfprintf_s_l_vfprintf_s_l _vfwprintf_s_l_vfwprintf_s_l

要求Requirements

例程所返回的值Routine 必需的标头Required header 可选标头Optional headers
vfprintf_s_vfprintf_s_lvfprintf_s, _vfprintf_s_l <stdio.h> 和 <stdarg.h><stdio.h> and <stdarg.h> <varargs.h>*<varargs.h>*
vfwprintf_s_vfwprintf_s_lvfwprintf_s, _vfwprintf_s_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.

有关其他兼容性信息,请参阅 兼容性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