_vcprintf、_vcprintf_l、_vcwprintf、_vcwprintf_l_vcprintf, _vcprintf_l, _vcwprintf, _vcwprintf_l

使用指向参数列表的指针编写格式化输出到控制台。Writes formatted output to the console by using a pointer to a list of arguments. 提供这些函数的更多安全版本;请参阅 _vcprintf_s、_vcprintf_s_l、_vcwprintf_s、_vcwprintf_s_lMore secure versions of these functions are available, see _vcprintf_s, _vcprintf_s_l, _vcwprintf_s, _vcwprintf_s_l.

重要

此 API 不能用于在 Windows 运行时中执行的应用程序。This API cannot be used in applications that execute in the Windows Runtime. 有关详细信息,请参阅通用 Windows 平台应用中不支持的 CRT 函数For more information, see CRT functions not supported in Universal Windows Platform apps.

语法Syntax

int _vcprintf(
   const char* format,
   va_list argptr
);
int _vcprintf_l(
   const char* format,
   locale_t locale,
   va_list argptr
);
int _vcwprintf(
   const wchar_t* format,
   va_list argptr
);
int _vcwprintf_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

写入的字符数,如果发生输出错误,则为一个负值。The number of characters written, or a negative value if an output error occurs. 如果format为空指针,则将调用无效参数处理程序,如参数验证中所述。If format is a null pointer, the invalid parameter handler is invoked, as described in Parameter Validation. 如果允许执行继续,则将errno设置为EINVAL ,并返回-1。If execution is allowed to continue, errno is set to EINVAL and -1 is returned.

备注Remarks

每个函数均采用一个指向参数列表的指针,然后将给定数据格式化并写入到控制台。Each of these functions takes a pointer to an argument list, then formats and writes the given data to the console. _vcwprintf_vcprintf的宽字符版本。_vcwprintf is the wide-character version of _vcprintf. 它将采用一个宽字符字符串作为参数。It takes a wide-character string as an argument.

使用 _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 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
_vtcprintf_vtcprintf _vcprintf_vcprintf _vcprintf_vcprintf _vcwprintf_vcwprintf
_vtcprintf_l_vtcprintf_l _vcprintf_l_vcprintf_l _vcprintf_l_vcprintf_l _vcwprintf_l_vcwprintf_l

要求Requirements

例程所返回的值Routine 必需的标头Required header 可选标头Optional headers
_vcprintf_vcprintf_l_vcprintf, _vcprintf_l <conio.h> 和 <stdarg.h><conio.h> and <stdarg.h> <varargs.h>*<varargs.h>*
_vcwprintf_vcwprintf_l_vcwprintf, _vcwprintf_l <conio.h> 或 <wchar.h> 和 <stdarg.h><conio.h> or <wchar.h>, and <stdarg.h> <varargs.h>*<varargs.h>*

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

有关其他兼容性信息,请参阅 兼容性For additional compatibility information, see Compatibility.

示例Example

// crt_vcprintf.cpp
// compile with: /c
#include <conio.h>
#include <stdarg.h>

// An error formatting function used to print to the console.
int eprintf(const char* format, ...)
{
    va_list args;
    va_start(args, format);
    int result = _vcprintf(format, args);
    va_end(args);
    return result;
}

int main()
{
    eprintf("(%d:%d): Error %s%d : %s\n", 10, 23, "C", 2111,
           "<some error text>");
    eprintf("    (Related to symbol '%s' defined on line %d).\n",
            "<symbol>", 5 );
}
(10,23): Error C2111 : <some error text>
    (Related to symbol '<symbol>' defined on line 5).

请参阅See also

流 I/OStream I/O
vprintf 函数vprintf Functions
_cprintf、_cprintf_l、_cwprintf、_cwprintf_l_cprintf, _cprintf_l, _cwprintf, _cwprintf_l
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