std:: fwide
| I/O manipulators | ||||
| Print functions (C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(C++20)
|
||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
| Synchronized Output | ||||
|
(C++20)
|
||||
| Types | ||||
| Error category interface | ||||
|
(C++11)
|
||||
|
(C++11)
|
| Types and objects | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
헤더 파일에 정의됨
<cwchar>
|
||
|
int
fwide
(
std::
FILE
*
stream,
int
mode
)
;
|
||
만약 mode > 0 이면, stream 을 wide-oriented로 만들려고 시도합니다. 만약 mode < 0 이면, stream 을 byte-oriented로 만들려고 시도합니다. 만약 mode == 0 이면, 스트림의 현재 방향만을 조회합니다.
스트림의 방향이 이미 결정된 경우(출력 실행 또는 이전 fwide 호출에 의해), 이 함수는 아무 작업도 수행하지 않습니다.
목차 |
매개변수
| stream | - | 수정하거나 조회할 C I/O 스트림에 대한 포인터 |
| mode | - | 0보다 큰 정수 값은 스트림을 와이드로 설정, 0보다 작은 값은 스트림을 내로우로 설정, 0은 조회만 수행 |
반환값
이 호출 이후 스트림이 와이드 지향(wide-oriented)이면 0보다 큰 정수, 바이트 지향(byte-oriented)이면 0보다 작은 정수, 방향성이 없으면 0을 반환합니다.
예제
다음 코드는 스트림 방향을 설정하고 재설정합니다.
#include <cstdio> #include <cstdlib> #include <cwchar> #include <iostream> void show_orientation(int n) { n < 0 ? std::wcout << "\tnarrow orientation\n" : n > 0 ? std::wcout << "\twide orientation\n" : std::wcout << "\tno orientation\n"; } void try_read(FILE* fp) { if (const int c = std::fgetc(fp); c == EOF) std::wcout << "\tnarrow character read failed\n"; else std::wcout << "\tnarrow character read '" << static_cast<char>(c) << "'\n"; if (const wint_t wc = std::fgetwc(fp); wc == WEOF) std::wcout << "\twide character read failed\n"; else std::wcout << "\twide character read '" << static_cast<wchar_t>(wc) << "'\n"; } int main() { enum fwide_orientation : int { narrow = -1, query, wide }; FILE* fp = std::fopen("main.cpp", "r"); if (!fp) { std::wcerr << "fopen() failed\n"; return EXIT_FAILURE; } std::wcout << "1) A newly opened stream has no orientation.\n"; show_orientation(std::fwide(fp, fwide_orientation::query)); std::wcout << "2) Establish byte orientation.\n"; show_orientation(std::fwide(fp, fwide_orientation::narrow)); try_read(fp); std::wcout << "3) Only freopen() can reset stream orientation.\n"; if (std::freopen("main.cpp", "r", fp) == NULL) { std::wcerr << "freopen() failed\n"; return EXIT_FAILURE; } std::wcout << "4) A reopened stream has no orientation.\n"; show_orientation(std::fwide(fp, fwide_orientation::query)); std::wcout << "5) Establish wide orientation.\n"; show_orientation(std::fwide(fp, fwide_orientation::wide)); try_read(fp); std::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 '#'
참고 항목
|
파일 열기
(함수) |
|
|
C documentation
for
fwide
|
|