函式
<cwchar>

fwide

int fwide (FILE* stream, int mode);
流的定向
確定 stream 的定向,如果它還沒有已建立的定向,則可以根據 mode 的值來設定。

開啟時,流沒有定向(包括 stdinstdoutstderr)。但是對其中一個執行的第一個 I/O 操作會自動設定其定向:如果是面向位元組的函式(在 <cstdio> 中定義),則流變為面向位元組;如果是面向寬字元的函式(在 <cwchar> 中定義),則流變為面向寬字元

透過呼叫此函式,可以在任何 I/O 操作之前顯式建立定向。在已經具有已建立的定向的 stream 上呼叫此函式不能改變它(只有在呼叫 freopen 後,具有已建立的定向的流才能更改它)。

可以透過將 mode 設為零來使用此函式來獲取流的當前定向。

引數

stream
FILE 物件指標,用於標識一個流。
mode
可以指定一個定向
  • 零的 mode 不會改變流的定向。
  • 大於零的 mode 會使流面向寬字元
  • 小於零的 mode 會使流面向位元組

返回值

該函式根據呼叫後的流定向返回值
  • 零值表示流還沒有定向。
  • 大於零的值表示流是面向寬字元的。
  • 小於零的值表示流是面向位元組的。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* fwide example */
#include <stdio.h>
#include <wchar.h>

int main ()
{
  FILE * pFile;
  int ret;

  pFile = fopen ("myfile.txt","a");
  if (pFile) {
    fwide (pFile,1);
    ret = fwide (pFile,0);
    if (ret>0) puts ("The stream is wide-oriented");
    else if (ret<0) puts ("The stream is byte-oriented");
    else puts ("The stream is not oriented");
    fclose (pFile);
  }
  return 0;
}

輸出
The stream is wide-oriented


另見