_putw
向流中写入一个整数。
int _putw(
int binint,
FILE *stream
);
参数
binint
将二进制整数输出。stream
指向 FILE 结构的指针。
返回值
返回写入的值。 一个EOF 的返回值可能会显示一个错误。 因为 EOF 也是一个合法的整数值,使用 ferror 验证错误。 如果 stream 是空指针,则会调用无效参数处理程序,如 参数验证 所述。 如果允许执行继续,则该函数设置 errno 为 EINVAL 并返回 EOF。
有关这些内容以及其他错误代码的详细信息,请参阅 _doserrno、errno、_sys_errlist 和 _sys_nerr。
备注
_putw 函数编写一个二进制值类型 int 到 流的当前位置。 _putw 不影响流中项的对齐也不采用任何特殊对齐。 _putw 主要是为与以前库兼容。 可移植性问题可能会和 _putw同时发生,因为 int 的大小和在int之内的字节的顺序字节跨系统不同。
要求
例程 |
必需的标头 |
---|---|
_putw |
<stdio.h> |
有关更多兼容性信息,请参见“简介”中的兼容性。
库
C 运行时库的所有版本。
示例
// crt_putw.c
/* This program uses _putw to write a
* word to a stream, then performs an error check.
*/
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
FILE *stream;
unsigned u;
if( fopen_s( &stream, "data.out", "wb" ) )
exit( 1 );
for( u = 0; u < 10; u++ )
{
_putw( u + 0x2132, stream ); /* Write word to stream. */
if( ferror( stream ) ) /* Make error check. */
{
printf( "_putw failed" );
clearerr_s( stream );
exit( 1 );
}
}
printf( "Wrote ten words\n" );
fclose( stream );
}
Output
Wrote ten words
.NET Framework 等效项
不适用。若要调用标准 C 函数,请使用 PInvoke。有关更多信息,请参见平台调用示例。