fwide
函数 <cwchar>
int fwide (FILE* stream, int mode);
流模式
确定流的模式,如果它还没有确定模式,可以根据mode的值设置。
当打开时,流没有区分模式(包括
stdin、
stdout
和
stderr)。
但是对一个流执行的第一个i/o操作会自动设置它的模式:
如果它是一个面向字节的函数(在<
cstdio>中定义),流就变成面向字节的;
如果它是一个面向宽字节的函数(在<
cwchar>中定义),流就会变成面向宽字节的。
通过调用这个函数,可以在任何i/o操作之前显式地确定模式。
在已经有确定模式的流上调用这个函数不能改变它的模式
(只有在调用了
freopen之后,才能改变它)。
该函数可以通过使用0作为mode来获取流的当前模式。
☲ 参数
stream
指向标识流的
FILE对象的指针。
mode
可以指定模式:
-
mode等于0,不会改变流的模式。
-
mode大于0,改变流为宽字符模式。
-
mode小于0,改变流为单字节模式。
☉ 返回值
函数在调用后根据流的模式返回一个值:
-
值为0,表示流还没有模式。
-
大于零的值表示流是宽字节模式的。
-
小于的值表示流是单字节模式的。
☣ 示例
/* 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
🍄 另请参阅