_vcprintf、_vcprintf_l、_vcwprintf、_vcwprintf_l

使用指向参数列表的指针编写格式化输出到控制台。 提供这些函数的更多安全版本;请参见 _vcprintf_s、_vcprintf_s_l、_vcwprintf_s、_vcwprintf_s_l

重要

此 API 不能用于在 Windows 运行时中执行的应用程序。有关详细信息,请参见 CRT functions not supported with /ZW(CRT 函数不支持使用/ZW)。

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
);

参数

  • format
    格式规范。

  • argptr
    指向参数列表的指针。

  • locale
    要使用的区域设置。

有关更多信息,请参见格式规范

返回值

读取字符数,或在发生错误时返回负值。 如果 format 是空指针,则会调用无效参数处理程序,如 参数验证 所述。 如果允许继续执行,将 EINVAL 设置为 errno,并返回 -1。

备注

每个函数通过指针指向参数列表,然后布局和编写特定数据到控制台。 _vcwprintf 是 _vcprintf的宽字符版本。 它采用宽字符字符串作为参数。

这些带有 _l 后缀的函数的版本相同,只不过它们使用传递的区域设置参数而不是当前区域设置。

安全说明安全说明

确保 format 不是用户定义的字符串。有关更多信息,请参见避免缓冲区溢出

一般文本例程映射

TCHAR.H 例程

未定义 _UNICODE & _MBCS

已定义 _MBCS

已定义 _UNICODE

_vtcprintf

_vcprintf

_vcprintf

_vcwprintf

_vtcprintf_l

_vcprintf_l

_vcprintf_l

_vcwprintf_l

要求

例程

必需的标头

可选标头

_vcprintf, _vcprintf_l

<conio.h> 和<stdarg.h>

<varargs.h>*

_vcwprintf, _vcwprintf_l

<stdio.h> 或 <wchar.h> 和 <stdarg.h>

<varargs.h>*

* 仅对 UNIX V 兼容性是必需的。

有关兼容性的更多信息,请参见兼容性

示例

// 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);
  return _vcprintf(format, args);
}

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 );
}
  

.NET Framework 等效项

System::Console::Write

请参见

参考

流 I/O

vprintf 函数

_cprintf、_cprintf_l、_cwprintf、_cwprintf_l

fprintf、_fprintf_l、fwprintf、_fwprintf_l

printf、_printf_l、wprintf、_wprintf_l

sprintf、_sprintf_l、swprintf、_swprintf_l、__swprintf_l

va_arg、va_copy、va_end、va_start