fwide
From cppreference.com
| ヘッダー <wchar.h> で定義 |
||
| int fwide( FILE* stream, int mode ); |
(C95 以降) | |
もし mode > 0 なら、stream をワイド指向にしようと試みます。もし mode < 0 なら、stream をバイト指向にしようと試みます。もし mode == 0 なら、ストリームの現在の方向性のみを問い合わせます。
ストリームの方向性が既に決定されている場合(出力の実行または以前の fwide の呼び出しによる)、この関数は何も行いません。
目次 |
[編集] パラメータ
| stream | - | 変更または問い合わせ対象の C I/O ストリームへのポインタ |
| モード | - | ストリームをワイドにするにはゼロより大きい整数値、ストリームをナローにするにはゼロより小さい整数値、または問い合わせのみの場合はゼロ |
[編集] 戻り値
この呼び出し後にストリームがワイド指向である場合はゼロより大きい整数、ストリームがバイト指向である場合はゼロより小さい整数、ストリームに方向性がない場合はゼロ
[編集] 例
以下のコードは、ストリームの方向性を設定およびリセットします。
このコードを実行
#include <stdio.h> #include <stdlib.h> #include <wchar.h> void show_orientation(int n) { n < 0 ? puts("\tnarrow orientation"): n > 0 ? puts("\twide orientation"): puts("\tno orientation"); } void try_read(FILE* fp) { int c = fgetc(fp); c == EOF ? printf("\tnarrow character read failed\n") : printf("\tnarrow character read '%c'\n", c); wint_t wc = fgetwc(fp); wc == WEOF ? printf("\twide character read failed\n") : printf("\twide character read '%lc'\n", wc); } int main(void) { enum fwide_orientation { narrow = -1, query, wide }; FILE* fp = fopen("main.cpp", "r"); if (!fp) { perror("fopen() failed"); return EXIT_FAILURE; } puts("1) A newly opened stream has no orientation."); show_orientation(fwide(fp, query)); puts("2) Establish byte orientation."); show_orientation(fwide(fp, narrow)); try_read(fp); puts("3) Only freopen() can reset stream orientation."); if (freopen("main.cpp", "r", fp) == NULL) { perror("freopen() failed"); return EXIT_FAILURE; } puts("4) A reopened stream has no orientation."); show_orientation(fwide(fp, query)); puts("5) Establish wide orientation."); show_orientation(fwide(fp, wide)); try_read(fp); fclose(fp); }
実行結果の例
1) A newly opened stream has no orientation.
no orientation
2) Establish byte orientation.
narrow orientation
narrow character read '#'
wide character read failed
3) Only freopen() can reset stream orientation.
4) A reopened stream has no orientation.
no orientation
5) Establish wide orientation.
wide orientation
narrow character read failed
wide character read '#'[編集] 参照
- C23標準 (ISO/IEC 9899:2024)
- 7.29.3.5 fwide 関数 (p: TBD)
- C17標準 (ISO/IEC 9899:2018)
- 7.29.3.5 fwide 関数 (p: 309)
- C11標準 (ISO/IEC 9899:2011)
- 7.29.3.5 fwide 関数 (p: 423)
- C99標準 (ISO/IEC 9899:1999)
- 7.24.3.5 fwide 関数 (p: 369)
[編集] 関連項目
| (C11) |
ファイルを開く (関数) |
| C++ ドキュメント for fwide
| |