_cprintf、_cprintf_l、_cwprintf、_cwprintf_l_cprintf, _cprintf_l, _cwprintf, _cwprintf_l

格式化并打印到控制台。Formats and prints to the console. 提供更为安全的版本;请参阅 _cprintf_s、_cprintf_s_l、_cwprintf_s、_cwprintf_s_lMore-secure versions are available; see _cprintf_s, _cprintf_s_l, _cwprintf_s, _cwprintf_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.


int _cprintf(   
   const char * format [, argument_list]  
int _cprintf_l(  
   const char * format,  
   locale_t locale [, argument_list]  
int _cwprintf(  
   const wchar * format [, argument_list]  
int _cwprintf_l(  
   const wchar * format,  
   locale_t locale [, argument_list]  


窗体控件字符串。Format-control string.

格式字符串的可选参数。Optional parameters for the format string.

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

返回值Return Value

打印的字符数。The number of characters printed.


这些函数会格式化一系列字符和值并将其直接输出到控制台,并使用 _putch 函数(_cwprintf_putwch)来输出字符。These functions format and print a series of characters and values directly to the console, using the _putch function (_putwch for _cwprintf) to output characters. 在每个自变量argument_list(如果有) 进行转换和输出中的相应格式规范根据formatEach argument in argument_list (if any) is converted and output according to the corresponding format specification in format. format自变量使用格式规范语法 printf 和 wprintf 函数The format argument uses the format specification syntax for printf and wprintf functions. 与不同fprintfprintf,和sprintf函数,两者_cprintf也不_cwprintf会换行字符将转换为回车换行符 (CR-LF) 组合输出时。Unlike the fprintf, printf, and sprintf functions, neither _cprintf nor _cwprintf translates line-feed characters into carriage return-line feed (CR-LF) combinations when output.

一个重要区别在于,_cwprintf显示 Unicode 字符在 Windows 中使用时。An important distinction is that _cwprintf displays Unicode characters when used in Windows. _cprintf 不同,_cwprintf 使用当前控制台区域设置。Unlike _cprintf, _cwprintf uses the current console locale settings.

这些带有 _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.

_cprintf 验证 format 参数。_cprintf validates the format parameter. 如果 format 为空指针,此函数将调用无效参数处理程序,如参数验证中所述。If format is a null pointer, the function invokes the invalid parameter handler, as described in Parameter Validation. 如果允许执行继续,则该函数将返回 -1 并将 errno 设置为 EINVALIf execution is allowed to continue, the function returns -1 and sets errno to EINVAL.


确保 format 不是用户定义的字符串。Ensure that format is not a user-defined string.

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

Tchar.h 例程Tchar.h routine 未定义 _UNICODE 和 _MBCS_UNICODE and _MBCS not defined 已定义 _MBCS_MBCS defined 已定义 _UNICODE_UNICODE defined
_tcprintf _cprintf _cprintf _cwprintf
_tcprintf_l _cprintf_l _cprintf_l _cwprintf_l


例程Routine 必需的标头Required header
_cprintf_cprintf_l_cprintf,_cprintf_l <conio.h><conio.h>
_cwprintf, _cwprintf_l_cwprintf, _cwprintf_l <conio.h><conio.h>

有关更多兼容性信息,请参阅 兼容性For more compatibility information, see Compatibility.


// crt_cprintf.c  
// compile with: /c  
// This program displays some variables to the console.  

#include <conio.h>  

int main( void )  
    int         i = -16,  
                h = 29;  
    unsigned    u = 62511;  
    char        c = 'A';  
    char        s[] = "Test";  

    // Note that console output does not translate \n as  
    // standard output does. Use \r\n instead.  
    _cprintf( "%d  %.4x  %u  %c %s\r\n", i, h, u, c, s );  
-16  001d  62511  A Test  

请参阅See Also

控制台和端口 I/O Console and Port I/O
_cscanf、_cscanf_l、_cwscanf、_cwscanf_l _cscanf, _cscanf_l, _cwscanf, _cwscanf_l
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
vfprintf、_vfprintf_l、vfwprintf、_vfwprintf_l vfprintf, _vfprintf_l, vfwprintf, _vfwprintf_l
_cprintf_s、_cprintf_s_l、_cwprintf_s、_cwprintf_s_l _cprintf_s, _cprintf_s_l, _cwprintf_s, _cwprintf_s_l
_cprintf_p、_cprintf_p_l、_cwprintf_p、_cwprintf_p_l _cprintf_p, _cprintf_p_l, _cwprintf_p, _cwprintf_p_l
格式规范语法:printf 和 wprintf 函数Format Specification Syntax: printf and wprintf Functions