_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 等效项

系统:: IO:: StreamWriter:: 写入

请参见

参考

流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