共用方式為


_putw

寫入資料至整數。

int _putw( 
   int binint, 
   FILE *stream  
);

參數

  • binint
    要輸出的二進位整數。

  • stream
    FILE 結構的指標。

傳回值

傳回寫入的值。 EOF 的傳回值可能表示錯誤。 由於 EOF 也是合法的整數值,請使用 ferror 驗證錯誤。 如果 stream 如 參數驗證 中所述為 null 指標,則叫用無效參數處理常式。 如果允許繼續執行,函式將 errno 設置為 EINVAL 並回傳 EOF

如需有關這些錯誤碼和其他錯誤碼的詳細資訊,請參閱 _doserrno、errno、_sys_errlist 和 _sys_nerr

備註

_putw 函式將 資料流目前位置寫入 int 型別的二進位值。_putw 不會影響項目的對齊方式在資料流中也不會假設任何特殊對齊。 _putw 是主要用於與前一個程式庫的相容性。 因為 int 的大小和位元組順序在 int 內的跨系統,不同可攜性問題可能發生的 _putw

需求

常式

必要的標頭

_putw

<stdio.h>

如需更多關於相容性的資訊,請參閱入門介紹中的 相容性 (Compatibility)

程式庫

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。如需詳細資訊,請參閱平台叫用範例

請參閱

參考

資料流 I/O

_getw