function
<cwchar>

fwide

int fwide (FILE* stream, int mode);
Stream orientation
Determines the orientation of stream, and if it has not yet an established orientation, it may be set, depending on the value of mode.

When open, streams have no orientation (including stdin, stdout and stderr). But the first i/o operation performed on one automatically sets its orientation: if it is a byte-oriented function (defined in <cstdio>), the stream becomes byte-oriented; if it is a wide-oriented function (defined in <cwchar>), the stream becomes wide-oriented.

By calling this function, the orientation can be explicitly established before any i/o operation. Calling this function on a stream that already has an orientation cannot change it (only after a call to freopen can a stream with an established orientation change it).

The function can be used to obtain the current orientation of a stream by using zero as mode.

Parameters

stream
Pointer to a FILE object that identifies a stream.
mode
May specify an orientation:
  • A mode of zero does not change the orientation of the stream.
  • A mode greater than zero makes the stream wide-oriented.
  • A mode less than zero makes the stream byte-oriented.

Return Value

The function returns a value depending on the stream orientation after the call:
  • A value of zero, indicates that the stream has no orientation yet.
  • A value greater than zero indicates that the stream is wide-oriented.
  • A value less than indicates that the stream is byte-oriented.

Example

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


Output:
The stream is wide-oriented

See also