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.


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   


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

格式规范。Format specification.

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

要使用的区域设置。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. 如果 streamformat 为 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 并将 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.


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

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

vfwprintf_svfprintf_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 vfprintf_s vfprintf_s vfwprintf_s
_vftprintf_s_l _vfprintf_s_l _vfprintf_s_l _vfwprintf_s_l


例程所返回的值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 in the Introduction.

请参阅See Also

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