?
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
在頭文件<wchar.h>中定義 | ||
---|---|---|
int fwide(FILE * stream,int mode); | (自C95以來(lái)) |
如果mode > 0
,試圖使stream
廣泛導(dǎo)向。如果mode < 0
,試圖使stream
字節(jié)為導(dǎo)向。如果mode==0
僅查詢流的當(dāng)前方向。
如果流的方向已經(jīng)確定(通過(guò)執(zhí)行輸出或通過(guò)先前調(diào)用fwide),則此函數(shù)不執(zhí)行任何操作。
流 | - | 指向要修改或查詢的CI / O流的指針 |
---|---|---|
模式 | - | 大于零的整數(shù)值將流設(shè)置為寬度,小于零以將流設(shè)置為窄,或者僅將零設(shè)置為僅查詢 |
如果流在此調(diào)用后面向全局,則為大于零的整數(shù),如果流在此調(diào)用后面向字節(jié),則小于零;如果流沒(méi)有定向,則為零。
以下代碼設(shè)置并重置流的方向。
#include <wchar.h>#include <stdio.h>#include <stdlib.h>void try_read(FILE* fp){ int c = fgetc(fp); if(c == EOF) puts("narrow character read failed"); else printf("narrow character read '%c'\n", c); wint_t wc = fgetwc(fp); if(wc == WEOF) puts("wide character read failed"); else printf("wide character read '%lc'\n", wc);}void show(int n){ if(n == 0) puts("no orientation"); else if (n < 0) puts("narrow orientation"); else puts("wide orientation");}int main(void){ FILE* fp = fopen("main.cpp","r"); if (!fp) { perror("fopen() failed"); return EXIT_FAILURE; } // A newly opened stream has no orientation. show(fwide(fp, 0)); // Establish byte orientation. show(fwide(fp, -1)); try_read(fp); // Only freopen() can reset stream orientation. if (freopen("main.cpp","r",fp) == NULL) { perror("freopen() failed"); return EXIT_FAILURE; } // A reopened stream has no orientation. show(fwide(fp, 0)); // Establish wide orientation. show(fwide(fp, 1)); try_read(fp); fclose(fp);}
可能的輸出:
no orientation narrow orientation narrow character read '#'wide character read failed no orientation wide orientation narrow character read failed wide character read '#'
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.29.3.5 fwide函數(shù)(p:423)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.24.3.5 fwide函數(shù)(p:369)