_getw_getw

从流中获取整数。Gets an integer from a stream.

语法Syntax

int _getw(
   FILE *stream
);

参数Parameters

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

返回值Return Value

_getw返回读取的整数值。_getw returns the integer value read. 返回值EOF指示存在错误或文件结尾。A return value of EOF indicates either an error or end of file. 但是,因为EOF值也是合法的整数值,请使用feofferror若要验证文件尾或错误条件。However, because the EOF value is also a legitimate integer value, use feof or ferror to verify an end-of-file or error condition. 如果NULL,则调用无效参数处理程序,如中所述参数验证If stream is NULL, the invalid parameter handler is invoked, as described in Parameter Validation. 如果允许执行继续,则errno设置为EINVAL和该函数将返回EOFIf execution is allowed to continue, errno is set to EINVAL and the function returns EOF.

备注Remarks

_Getw函数将读取的下一步的二进制值的类型int与关联的文件从并递增关联的文件指针 (如果有) 以点为下一步的未读字符。The _getw function reads the next binary value of type int from the file associated with stream and increments the associated file pointer (if there is one) to point to the next unread character. _getw不会采用任何特殊的对齐方式的流中的项。_getw does not assume any special alignment of items in the stream. 移植问题可能会出现 _getw因为的大小int类型和中的字节顺序int类型因系统而异。Problems with porting can occur with _getw because the size of the int type and the ordering of bytes within the int type differ across systems.

要求Requirements

例程Routine 必需的标头Required header
_getw_getw <stdio.h><stdio.h>

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

示例Example

// crt_getw.c
// This program uses _getw to read a word
// from a stream, then performs an error check.

#include <stdio.h>
#include <stdlib.h>

int main( void )
{
   FILE *stream;
   int i;

   if( fopen_s( &stream, "crt_getw.txt", "rb" ) )
      printf( "Couldn't open file\n" );
   else
   {
      // Read a word from the stream:
      i = _getw( stream );

      // If there is an error...
      if( ferror( stream ) )
      {
         printf( "_getw failed\n" );
         clearerr_s( stream );
      }
      else
         printf( "First data word in file: 0x%.4x\n", i );
      fclose( stream );
   }
}

输入:crt_getw.txtInput: crt_getw.txt

Line one.
Line two.

输出Output

First data word in file: 0x656e694c

请参阅See also

流 I/OStream I/O
_putw_putw