_printf_p、_printf_p_l、_wprintf_p、_wprintf_p_l
打印格式化输出到标准输出流,并启用参数用于格式字符串排序的规范。
int _printf_p(
const char *format [,
argument]...
);
int _printf_p_l(
const char *format,
locale_t locale [,
argument]...
);
int _wprintf_p(
const wchar_t *format [,
argument]...
);
int _wprintf_p_l(
const wchar_t *format,
locale_t locale [,
argument]...
);
参数
format
格式控件。argument
可选参数。locale
要使用的区域设置。
返回值
返回打印的字符数,或在发生错误时返回负值。
备注
_printf_p 函数对一系列字符和值设置格式并将其打印到标准输出流 stdout 中。 如果参数紧跟 format 字符串,则 format 字符串必须包含确定参数输出格式的规范。( 见printf_p 位置参数).
在 _printf_p 和 printf_s 的不同之处在于 _printf_p 支持位置参数,允许指定排序参数用于格式字符串。 有关详细信息,请参阅printf_p 位置参数。
_wprintf_p 是 _printf_p的宽字符版本;如果流在 ANSI 模式下打开它们具有相同的行为。 _printf_p 当前不支持输出到 UNICODE 流。
这些带有 _l 后缀的函数的版本相同,只不过它们使用传递的区域设置参数而不是当前线程区域设置。
安全说明 |
---|
确保 format 不是用户定义的字符串。 |
如果 format 或 argument 是 NULL,或格式字符串包含无效格式字符,_printf_p 和 _wprintf_p 函数调用无效参数处理程序,如 参数验证所述。 如果允许执行继续,则该函数返回 -1 并将 errno 设置为 EINVAL。
一般文本例程映射
Tchar.h 例程 |
未定义 _UNICODE 和 _MBCS |
已定义 _MBCS |
已定义 _UNICODE |
---|---|---|---|
_tprintf_p |
_printf_p |
_printf_p |
_wprintf_p |
_tprintf_p_l |
_printf_p_l |
_printf_p_l |
_wprintf_p_l |
要求
例程 |
必需的标头 |
---|---|
_printf_p, _printf_p_l |
<stdio.h> |
_wprintf_p, _wprintf_p_l |
<stdio.h> 或 <wchar.h> |
控制台在 Windows 应用商店 应用程序中不受支持。 与控制台 stdin、stdout 和 stderr 关联的标准流句柄必须重定向,然后 C 运行时函数才可以在 Windows 应用商店 应用程序中使用它们。 有关兼容性的更多信息,请参见兼容性。
示例
// crt_printf_p.c
// This program uses the _printf_p and _wprintf_p
// functions to choose the order in which parameters
// are used.
#include <stdio.h>
int main( void )
{
// Positional arguments
_printf_p( "Specifying the order: %2$s %3$s %1$s %4$s %5$s.\n",
"little", "I'm", "a", "tea", "pot");
// Resume arguments
_wprintf_p( L"Reusing arguments: %1$d %1$d %1$d %1$d\n", 10);
// Width argument
_printf_p("Width specifiers: %1$*2$s", "Hello\n", 10);
}
.NET Framework 等效项
请参见
参考
_fprintf_p、_fprintf_p_l、_fwprintf_p、_fwprintf_p_l
fprintf、_fprintf_l、fwprintf、_fwprintf_l
fprintf_s、_fprintf_s_l、fwprintf_s、_fwprintf_s_l
scanf、_scanf_l、wscanf、_wscanf_l
scanf_s、_scanf_s_l、wscanf_s、_wscanf_s_l
_sprintf_p、_sprintf_p_l、_swprintf_p、_swprintf_p_l
sprintf、_sprintf_l、swprintf、_swprintf_l、__swprintf_l