Share via


_fprintf_p、_fprintf_p_l、_fwprintf_p、_fwprintf_p_l

将格式化的数据打印到流。

int _fprintf_p( 
   FILE *stream,
   const char *format [,
   argument ]...
);
int _fprintf_p_l( 
   FILE *stream,
   const char *format,
   locale_t locale [,
   argument ]...
);
int _fwprintf_p( 
   FILE *stream,
   const wchar_t *format [,
   argument ]...
);
int _fwprintf_p_l( 
   FILE *stream,
   const wchar_t *format,
   locale_t locale [,
   argument ]...
);

参数

  • stream
    指向 FILE结构的指针。

  • format
    窗体控件字符串。

  • argument
    可选参数。

  • locale
    要使用的区域设置。

返回值

在输出错误时,_fprintf_p 和 _fwprintf_p 返回写入的字符数或返回负值。

备注

_fprintf_p格式化并输出一系列字符和值到输出stream. 每个函数 argument(如果有)根据 format 中相应的格式规范进行转换和输出。 对于 _fprintf_p,format 参数与_printf_p相同的语法和用法。 这些函数支持位置参数,这意味着格式字符串使用的参数的顺序可更改。 有关位置参数的更多信息,请参见printf_p 位置参数

_fwprintf_p 是 _fprintf_p 的宽字符版本;_fwprintf_p,format是宽字符串。 如果流在 ANSI 模式中打开,这些函数具有相同的行为。 _fprintf_p 当前不支持输出到 UNICODE 流。

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

安全说明安全说明

确保 format 不是用户定义的字符串。

这些函数与不安全版本相同 (参见 fprintf、_fprintf_l、fwprintf、_fwprintf_l),验证它们的参数并调用的参数无效处理程序,如 参数验证所述,如果stream 或 format 为 null 指针,或如果有任何一种未知或严格的格式说明符。 如果允许继续执行,则这些函数返回-1,并将errno设置为EINVAL。

一般文本例程映射

Tchar.h 例程

未定义 _UNICODE 和 _MBCS

已定义 _MBCS

已定义 _UNICODE

_ftprintf_p

_fprintf_p

_fprintf_p

_fwprintf_p

_ftprintf_p_l

_fprintf_p_l

_fprintf_p_l

_fwprintf_p_l

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

要求

功能

必需的标头

_fprintf_p, _fprintf_p_l

<stdio.h>

_fwprintf_p, _fwprintf_p_l

<stdio.h> 或 <wchar.h>

有关更多兼容性信息,请参见“简介”中的兼容性

示例

// crt_fprintf_p.c
// This program uses _fprintf_p to format various
// data and print it to the file named FPRINTF_P.OUT. It
// then displays FPRINTF_P.OUT on the screen using the system
// function to invoke the operating-system TYPE command.
// 

#include <stdio.h>
#include <process.h>


int main( void )
{
    FILE    *stream = NULL;
    int     i = 10;
    double  fp = 1.5;
    char    s[] = "this is a string";
    char    c = '\n';

    // Open the file
    if ( fopen_s( &stream, "fprintf_p.out", "w" ) == 0)
    {
        // Format and print data
        _fprintf_p( stream, "%2$s%1$c", c, s );
        _fprintf_p( stream, "%d\n", i );
        _fprintf_p( stream, "%f\n", fp );

        // Close the file
        fclose( stream );
    }

    // Verify our data
    system( "type fprintf_p.out" );
}
  

.NET Framework 等效项

System::IO::StreamWriter::Write

请参见

参考

流 I/O

_cprintf、_cprintf_l、_cwprintf、_cwprintf_l

fscanf、_fscanf_l、fwscanf、_fwscanf_l

sprintf、_sprintf_l、swprintf、_swprintf_l、__swprintf_l

printf_p 位置参数

_cprintf_p、_cprintf_p_l、_cwprintf_p、_cwprintf_p_l

_cprintf_s、_cprintf_s_l、_cwprintf_s、_cwprintf_s_l

printf_p 位置参数

fscanf_s、_fscanf_s_l、fwscanf_s、_fwscanf_s_l