_putw_putw

将一个整数写入到流中。Writes an integer to a stream.

语法Syntax

int _putw(
   int binint,
   FILE *stream
);

参数Parameters

binintbinint
要输出的二进制整数。Binary integer to be output.

streamstream
指向文件结构的指针。Pointer to the FILE structure.

返回值Return Value

返回写入的值。Returns the value written. 返回值EOF可能指示错误。A return value of EOF might indicate an error. 由于EOF也是合法的整数值,请使用ferror来验证错误。Because EOF is also a legitimate integer value, use ferror to verify an error. 如果stream为空指针,则将调用无效参数处理程序,如参数验证中所述。If stream is a null pointer, the invalid parameter handler is invoked, as described in Parameter Validation. 如果允许执行继续,则此函数会将errno设置为EINVAL并返回EOFIf execution is allowed to continue, this function sets errno to EINVAL and returns EOF.

有关这些及其他错误代码的信息,请参阅 _doserrno、errno、_sys_errlist 和 _sys_nerrFor information about these and other error codes, see _doserrno, errno, _sys_errlist, and _sys_nerr.

备注Remarks

_Putw函数将int类型的二进制值写入流的当前位置 The _putw function writes a binary value of type int to the current position of stream. _putw不会影响流中的项的对齐方式,也不会采用任何特殊的对齐方式。_putw does not affect the alignment of items in the stream nor does it assume any special alignment. _putw主要用于与以前的库兼容。_putw is primarily for compatibility with previous libraries. _Putw可能会出现可移植性问题,因为 int 和 int中的字节顺序的大小在不同系统之间存在差异。Portability problems might occur with _putw because the size of an int and the ordering of bytes within an int differ across systems.

要求Requirements

例程所返回的值Routine 必需的标头Required header
_putw_putw <stdio.h><stdio.h>

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

Libraries

C 运行时库的所有版本。All versions of the C run-time libraries.

示例Example

// 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 );
}

OutputOutput

Wrote ten words

请参阅See also

流 I/OStream I/O
_getw_getw