fwide
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <wchar.h> で定義
|
||
int fwide( FILE *stream, int mode ); |
(C95以上) | |
mode > 0 の場合は、 stream をワイド指向にしようと試みます。 mode < 0 の場合は、 stream をナロー指向にしようと試みます。 mode==0 の場合は、ストリームの現在の指向の照会のみを行います。
(出力を行うことによって、または以前の fwide の呼び出しによって) ストリームの指向がすでに決定されている場合、この関数は何もしません。
引数
| stream | - | 変更または照会する C の入出力ストリームを指すポインタ |
| mode | - | ストリームをワイドに設定する場合はゼロより大きな整数値、ストリームをナローに設定するにはゼロより小さな整数値、照会するだけの場合はゼロ |
戻り値
この呼び出しの後、ストリームがワイド指向であればゼロより大きな整数値、この呼び出しの後、ストリームがナロー指向であればゼロのより小さな値、ストリームが指向を持っていなければゼロ。
例
以下のコードはストリームの指向をセットおよびリセットします。
Run this code
#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 standard (ISO/IEC 9899:2011):
- 7.29.3.5 The fwide function (p: 423)
- C99 standard (ISO/IEC 9899:1999):
- 7.24.3.5 The fwide function (p: 369)
関連項目
(C11) |
ファイルを開きます (関数) |
fwide の C++リファレンス
|